codebarista / laravel-echarts
从 Apache ECharts 创建图像。
1.1.0
2024-03-12 19:42 UTC
Requires
- laravel/framework: ^10.0|^11.0
Requires (Dev)
- laravel/pint: ^1.0
- orchestra/testbench: ^8.0|^9.0
- pestphp/pest-plugin-laravel: ^2.0
README
使用 Laravel 和 Node.js 服务器端渲染 Apache ECharts。将图表图像作为 png、jpg、pdf 或 svg 存储到存储中。
要求
- Node.js 和 npm
安装
安装包
composer require codebarista/laravel-echarts
安装节点模块
php artisan codebarista:node-echarts install
为了更新,将命令添加到根 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"
安装 pngcrush(可选)
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], ], ], ]);
配置
从配置文件中覆盖默认属性
$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: [...]);
许可
MIT 许可证(MIT)。有关更多信息,请参阅许可文件。