Server-side rendering of Apache ECharts with Laravel and Node.js. Render chart images as png, jpg, pdf or svg to storage.
- Node.js and npm
composer require codebarista/laravel-echarts
php artisan codebarista:node-echarts install
For updates it would be a good idea to add the command to the root composer.json.
{
"scripts": {
"post-update-cmd": [
"@php artisan vendor:publish --tag=laravel-assets --ansi --force",
"@php artisan codebarista:node-echarts install"
]
},
}
php artisan vendor:publish --tag="config" --provider="Codebarista\LaravelEcharts\EchartsServiceProvider"
apt install pngcrush
use Codebarista\LaravelEcharts\Actions\StoreChartImage;
// ...
StoreChartImage::make()->handle([
'title' => [
'text' => 'Basic Bar Chart',
],
'xAxis' => [
'type' => 'category',
'data' => ['Shirts', 'Cardigans', 'Chiffons', 'Pants', 'Heels', 'Socks'],
],
'yAxis' => [
'type' => 'value',
],
'series' => [
[
'type' => 'bar',
'data' => [5, 20, 36, 10, 10, 20],
],
],
]);
Overwrite the default attributes from config file:
$action = StoreChartImage::make()
->baseOptionPath(resource_path('echarts/base-option.mjs')) // base chart to be merged
->mimeType(MimeTypes::PNG) // PNG, JPG, PDF, SVG
->optimize(true) // optimize with pngcrush
->filePath('app/public') // storage path
->fileName('simple-bar-chart') // w/o extension
->width(600) // image width
->height(600); // image height
$action->handle(options: [...]);
The MIT License (MIT). Please see License File for more information.