farshidrezaei / chartio
Laravel 的简单静态图表生成器
v1.6.0
2021-12-06 07:57 UTC
Requires
- spatie/browsershot: ^3.50
README
Chartio 是 Laravel 的静态图表生成器。Chartio 使用 highchart.js
生成图表,并通过 spatie/browsershot
获取截图。
请根据以下文档安装和配置 browsershot:[此处](https://github.com/spatie/browsershot)。
进行中
- 云图表
- 柱状图
- 条形图
- 折线图
- 饼图
- 环形图
- 抽象图表(可定制)
安装
composer
composer require farshidrezaei/chartio
Chartio 环境
将以下配置设置到 .env
文件中,并替换为您的已安装 node 和 npm 路径
NODE_PATH= NPM_PATH=
定制
发布配置文件
php artisan vendor:publish --provider="FarshidRezaei\Chartio\Providers\ChartioServiceProvider" --tag="config"
发布视图文件
php artisan vendor:publish --provider="FarshidRezaei\Chartio\Providers\ChartioServiceProvider" --tag="views"
使用方法
以下是一个快速示例
use FarshidRezaei\Chartio\Services\Chartio; $data = [ ['title'=>'foo','count'=>1234], ['title'=>'bar','count'=>5475], ['title'=>'baz','count'=>452], ['title'=>'don','count'=>1457], ['title'=>'shi','count'=>2458], ['title'=>'iran','count'=>3115], ['title'=>'persian','count'=>455], ['title'=>'farshid','count'=>5126], ['title'=>'lifeweb','count'=>1111], ]; $imagePath= Chartio::make( 'cloud' ) ->rtl() ->color('#13b6b9') ->colorSet([ "#009299", "#1AD7DB", "#589DFB", "#5EDFFF", "#B7E778" ]) ->title('Chartio Example') ->description('This is Chartio Example') ->xAxisField( 'title' ) ->yAxisField( 'count' ) ->data( $data ) ->generate() ->save( Storage::path( 'chartio-example.png' ) );
文件将保存在您输入的路径中。
每个图表的数据示例
柱状图
$data = [ 'labels' => [ '1999', '2000', '2005' ], 'series' => [ [ 'title' => 'foo', 'data' => [ 10, 5, 30 ], ], [ 'title' => 'bar', 'data' => [ 15, 26, 5 ], ], ], ]; $imagePath= Chartio::make( 'bar' ) ->rtl() ->color('#13b6b9') ->colorSet([ "#009299", "#1AD7DB", "#589DFB", "#5EDFFF", "#B7E778" ]) ->title('Chartio Example') ->description('This is Chartio Example') ->data( $data ) ->generate() ->save( Storage::path( 'chartio-example.png' ) );
导出示例
条形图
$data = [ 'labels' => [ '1999', '2000', '2005' ], 'series' => [ [ 'title' => 'foo', 'data' => [ 10, 5, 30 ], ], [ 'title' => 'bar', 'data' => [ 15, 26, 5 ], ], ], ]; $imagePath= Chartio::make( 'column' ) ->rtl() ->color('#13b6b9') ->colorSet([ "#009299", "#1AD7DB", "#589DFB", "#5EDFFF", "#B7E778" ]) ->title('Chartio Example') ->description('This is Chartio Example') ->data( $data ) ->generate() ->save( Storage::path( 'chartio-example.png' ) );
导出示例
折线图
$data = [ 'labels' => [ '1999', '2000', '2005' ], 'series' => [ [ 'title' => 'foo', 'data' => [ 10, 5, 30 ], ], [ 'title' => 'bar', 'data' => [ 15, 26, 5 ], ], ], ]; $imagePath= Chartio::make( 'line' ) ->rtl() ->color('#13b6b9') ->colorSet([ "#009299", "#1AD7DB", "#589DFB", "#5EDFFF", "#B7E778" ]) ->title('Chartio Example') ->description('This is Chartio Example') ->data( $data ) ->generate() ->save( Storage::path( 'chartio-example.png' ) );
导出示例
饼图
$data = [ ['title'=>'foo','count'=>1234], ['title'=>'bar','count'=>125], ['title'=>'baz','count'=>564], ]; $imagePath= Chartio::make( 'pie' ) ->rtl() ->color('#13b6b9') ->colorSet([ "#009299", "#1AD7DB", "#589DFB", "#5EDFFF", "#B7E778" ]) ->title('Chartio Example') ->description('This is Chartio Example') ->xAxisField( 'title' ) ->yAxisField( 'count' ) ->data( $data ) ->generate() ->save( Storage::path( 'chartio-example.png' ) );
导出示例
环形图
$data = [ ['title'=>'foo','count'=>1234], ['title'=>'bar','count'=>125], ['title'=>'baz','count'=>564], ]; $imagePath= Chartio::make( 'donut' ) ->rtl() ->color('#13b6b9') ->colorSet([ "#009299", "#1AD7DB", "#589DFB", "#5EDFFF", "#B7E778" ]) ->title('Chartio Example') ->description('This is Chartio Example') ->xAxisField( 'title' ) ->yAxisField( 'count' ) ->data( $data ) ->generate() ->save( Storage::path( 'chartio-example.png' ) );
导出示例
云图表
$data = [ ['title'=>'foo','count'=>1234], ['title'=>'bar','count'=>5475], ['title'=>'baz','count'=>452], ]; $imagePath= Chartio::make( 'cloud' ) ->rtl() ->color('#13b6b9') ->colorSet([ "#009299", "#1AD7DB", "#589DFB", "#5EDFFF", "#B7E778" ]) ->title('Chartio Example') ->description('This is Chartio Example') ->xAxisField( 'title' ) ->yAxisField( 'count' ) ->data( $data ) ->generate() ->save( Storage::path( 'chartio-example.png' ) );
导出示例
抽象图表
$imagePath = Chartio::make( 'abstract' ) ->rtl() ->title( 'Chartio Example' ) ->description( 'This is Chartio Example' ) ->chartOptions( [ 'chart' => [ 'type' => 'arearange', 'zoomType' => 'x', 'scrollablePlotArea' => [ 'minWidth' => 600, 'scrollPositionX' => 1, ], ], 'credits' => [ 'enabled' => false, ], 'title' => [ 'text' => 'Temperature variation by day', ], 'xAxis' => [ 'type' => 'datetime', 'accessibility' => [ 'rangeDescription' => 'Range: Jan 1st 2017 to Dec 31 2017.', ], ], 'yAxis' => [ 'title' => [ 'text' => null, ], ], 'tooltip' => [ 'crosshairs' => true, 'shared' => true, 'valueSuffix' => '°C', 'xDateFormat' => '%A, %b %e', ], 'legend' => [ 'enabled' => false, ], 'series' => [ [ 'name' => 'Temperatures', 'data' => [ [ 1483232400000, 1.4, 4.7, ], [ 1483318800000, -1.3, 1.9, ], [ 1483405200000, -0.7, 4.3, ], [ 1483491600000, -5.5, 3.2, ], ], ], ], ] ) ->generate() ->save( Storage::path( 'chartio-example.png' ) );
导出示例
许可证
MIT 许可证(MIT)。有关更多信息,请参阅许可证文件。