https://github.com/codebarista/laravel-echarts
Store Apache ECharts as image
https://github.com/codebarista/laravel-echarts
echarts laravel php
Last synced: 3 months ago
JSON representation
Store Apache ECharts as image
- Host: GitHub
- URL: https://github.com/codebarista/laravel-echarts
- Owner: codebarista
- License: mit
- Created: 2024-02-13T21:11:30.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-03-30T13:30:30.000Z (about 2 years ago)
- Last Synced: 2025-12-14T22:20:06.195Z (6 months ago)
- Topics: echarts, laravel, php
- Language: PHP
- Homepage:
- Size: 16.6 KB
- Stars: 2
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Laravel Echarts
Server-side rendering of [Apache ECharts](https://echarts.apache.org/) with Laravel and Node.js. Render chart images as
png, jpg, pdf or svg to storage.
## Requirements
- Node.js and npm
## Installation
### Install package
```shell
composer require codebarista/laravel-echarts
```
### Install node modules
```shell
php artisan codebarista:node-echarts install
```
For updates it would be a good idea to add the command to the root composer.json.
```json
{
"scripts": {
"post-update-cmd": [
"@php artisan vendor:publish --tag=laravel-assets --ansi --force",
"@php artisan codebarista:node-echarts install"
]
},
}
```
### Publish config (optional)
```shell
php artisan vendor:publish --tag="config" --provider="Codebarista\LaravelEcharts\EchartsServiceProvider"
```
### Install pngcrush (optional)
- https://pmt.sourceforge.io/pngcrush
```shell
apt install pngcrush
```
## Usage
### Store Chart Image
```php
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:
```php
$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](LICENSE) for more information.