A PHP library to create svg charts for your data. No external js, no external dependancies just plain svg images
danielpetrica/svg-charts is a Laravel package for a php library to create svg charts for your data. no external js, no external dependancies just plain svg images.
It currently has 1 GitHub stars and 0 downloads on Packagist.
Install it with composer require danielpetrica/svg-charts.
Discover more Laravel packages by danielpetrica
or browse all Laravel packages to compare alternatives.
Last updated
A PHP library to create SVG charts for your data. No external JavaScript, no external dependencies - just plain SVG images.
Security Note: For saving SVG as an image, security checks are delegated to the user. Make sure to perform all necessary security checks!
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"
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],
];
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');
<div class="chart-container">
{!! $chart->render() !!}
</div>
// Set custom colors for subjects
$chart->setColors([
'Product A' => '#FF5733',
'Product B' => '#33FF57'
]);
Run the test suite:
composer test
See CHANGELOG for version history.
Contributions welcome! See CONTRIBUTING for guidelines.
Please report vulnerabilities via our security policy.
MIT License. See LICENSE 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.