PHPackages                             danielpetrica/svg-charts - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Image &amp; Media](/categories/media)
4. /
5. danielpetrica/svg-charts

ActiveLibrary[Image &amp; Media](/categories/media)

danielpetrica/svg-charts
========================

A PHP library to create svg charts for your data. No external js, no external dependancies just plain svg images

10[4 PRs](https://github.com/danielpetrica/Svg_charts/pulls)PHPCI passing

Since Oct 13Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/danielpetrica/Svg_charts)[ Packagist](https://packagist.org/packages/danielpetrica/svg-charts)[ RSS](/packages/danielpetrica-svg-charts/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (5)Used By (0)

Svg Charts - Create charts as plain SVG images
==============================================

[](#svg-charts---create-charts-as-plain-svg-images)

[![Latest Version on Packagist](https://camo.githubusercontent.com/34c514efa0e1ca54c905c82ad102d538bee8f4b0987f2f29c9a99db92b97477d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f64616e69656c706574726963612f7376672d6368617274732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/danielpetrica/svg-charts)[![GitHub Tests Action Status](https://camo.githubusercontent.com/ef5548c88c4cfd966eca27bd5068ca4c8f548dbbea5e420a8fa7078dcdf03599/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f64616e69656c706574726963612f7376675f6368617274732f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/danielpetrica/svg_charts/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/65547482a099285a604364fac02a138f9d9593056cedc238bfb560b89ea7493c/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f64616e69656c706574726963612f7376675f6368617274732f6669782d7068702d636f64652d7374796c652d6973737565732e796d6c3f6272616e63683d6d61696e266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/danielpetrica/svg_charts/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/8d6708bd56b6bd4d75191eccf77a8c2c37e93188cd645b79aa9a363dd924c7e9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f64616e69656c706574726963612f7376672d6368617274732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/danielpetrica/svg-charts)

A PHP library to create SVG charts for your data. No external JavaScript, no external dependencies - just plain SVG images.

Features
--------

[](#features)

- Generates bar charts in SVG format based on array data
- Each bar represents a value (count) associated with a subject, grouped by time intervals
- Minimal graphical representations without external dependencies or JavaScript libraries
- Output can be passed to Blade for on-screen display
- Built-in color scheme with automatic color generation

> **Security Note**: For saving SVG as an image, security checks are delegated to the user. Make sure to perform all necessary security checks!

Installation
------------

[](#installation)

Install the package via composer:

```
composer require danielpetrica/svg-charts
```

Publish and run migrations:

```
php artisan vendor:publish --tag="svg-charts-migrations"
php artisan migrate
```

Publish the config file:

```
php artisan vendor:publish --tag="svg-charts-config"
```

Config file contents (`config/svg-charts.php`):

```
return [
    // Configuration options will go here
];
```

Optionally publish views:

```
php artisan vendor:publish --tag="svg-charts-views"
```

Usage
-----

[](#usage)

### Data Format Requirements

[](#data-format-requirements)

Data must be provided as an array of associative arrays with these keys:

```
[
    'subject'   => (string) Subject/category name,
    'timeSlice' => (string) Time interval (e.g., "January", "2024-04"),
    'count'     => (int) The numeric value to display
]
```

Example dataset:

```
$data = [
    ['subject' => 'Product A', 'timeSlice' => 'January', 'count' => 25],
    ['subject' => 'Product B', 'timeSlice' => 'January', 'count' => 15],
    ['subject' => 'Product A', 'timeSlice' => 'February', 'count' => 30],
    ['subject' => 'Product B', 'timeSlice' => 'February', 'count' => 22],
];
```

### Basic Usage

[](#basic-usage)

```
use DanielPetrica\SvgCharts\SvgCharts;

// Create chart instance
$chart = new SvgCharts($data, 'Monthly Sales');

// Set dimensions (width, height in pixels)
$chart->setDimensions(800, 400);

// Output to screen
echo $chart->render();

// Save to file
$chart->renderToFile('chart.svg');
```

### Laravel Blade Integration

[](#laravel-blade-integration)

```

    {!! $chart->render() !!}

```

### Customizing Colors

[](#customizing-colors)

```
// Set custom colors for subjects
$chart->setColors([
    'Product A' => '#FF5733',
    'Product B' => '#33FF57'
]);
```

Testing
-------

[](#testing)

Run the test suite:

```
composer test
```

Changelog
---------

[](#changelog)

See [CHANGELOG](CHANGELOG.md) for version history.

Contributing
------------

[](#contributing)

Contributions welcome! See [CONTRIBUTING](CONTRIBUTING.md) for guidelines.

Security
--------

[](#security)

Please report vulnerabilities via [our security policy](../../security/policy).

Credits
-------

[](#credits)

- [Daniel, Andrei-Daniel Petrica](https://github.com/danielpetrica)

License
-------

[](#license)

MIT License. See [LICENSE](LICENSE.md) for details.

```

This markdown file includes:

1. Header with badges
2. Clear feature list
3. Security notice
4. Installation instructions
5. Usage examples with code blocks
6. Data format requirements
7. Testing information
8. Standard open-source sections (Changelog, Contributing, Security, Credits, License)

The formatting uses proper markdown syntax for:
- Headers (`#`, `##`, `###`)
- Code blocks (```)
- Lists (`-`)
- Emphasis (`**`)
- Links (`[text](url)`)
- Escape characters where needed

The content is organized logically from high-level overview to specific implementation details.

```

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance60

Regular maintenance activity

Popularity2

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity18

Early-stage or recently created project

 Bus Factor1

Top contributor holds 76% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/a5d82612a474f480b832567911d378cef4d4029dbbfd6747f723ba1af87aa155?d=identicon)[danielpetrica](/maintainers/danielpetrica)

---

Top Contributors

[![danielpetrica](https://avatars.githubusercontent.com/u/4850686?v=4)](https://github.com/danielpetrica "danielpetrica (19 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (3 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (3 commits)")

### Embed Badge

![Health badge](/badges/danielpetrica-svg-charts/health.svg)

```
[![Health](https://phpackages.com/badges/danielpetrica-svg-charts/health.svg)](https://phpackages.com/packages/danielpetrica-svg-charts)
```

###  Alternatives

[milon/barcode

Barcode generator like Qr Code, PDF417, C39, C39+, C39E, C39E+, C93, S25, S25+, I25, I25+, C128, C128A, C128B, C128C, 2-Digits UPC-Based Extention, 5-Digits UPC-Based Extention, EAN 8, EAN 13, UPC-A, UPC-E, MSI (Variation of Plessey code)

1.5k13.3M39](/packages/milon-barcode)[bkwld/croppa

Image thumbnail creation through specially formatted URLs for Laravel

510496.0k23](/packages/bkwld-croppa)[goat1000/svggraph

Generates SVG graphs

132849.6k3](/packages/goat1000-svggraph)[cohensive/embed

Media Embed (for Laravel or as a standalone).

120370.4k](/packages/cohensive-embed)[netresearch/rte-ckeditor-image

Image support in CKEditor for the TYPO3 ecosystem - by Netresearch

63991.3k4](/packages/netresearch-rte-ckeditor-image)[humanmade/tachyon-plugin

Rewrites WordPress image URLs to use Tachyon

87338.5k2](/packages/humanmade-tachyon-plugin)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
