jcsaunders / laravel-echarts
Create an image from Apache ECharts.
v1.0.0
2024-04-21 04:24 UTC
Requires
- codebarista/laravel-essentials: ^1.2
- laravel/framework: ^10.0|^11.0
Requires (Dev)
- laravel/pint: ^1.0
- orchestra/testbench: ^8.0|^9.0
- pestphp/pest-plugin-laravel: ^2.0
This package is not auto-updated.
Last update: 2025-03-10 07:11:01 UTC
README
Server-side rendering of Apache ECharts with Laravel and Node.js. Render chart images as png, jpg, pdf or svg to storage.
Requirements
- Node.js and npm
Installation
Install package
composer require codebarista/laravel-echarts
Install node modules
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" ] }, }
Publish config (optional)
php artisan vendor:publish --tag="config" --provider="Codebarista\LaravelEcharts\EchartsServiceProvider"
Install pngcrush (optional)
apt install pngcrush
Usage
Store Chart Image
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], ], ], ]);
Config
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: [...]);
License
The MIT License (MIT). Please see License File for more information.