diagro/lib_php_chart
最新稳定版本:1.3.2
Composer 安装命令:
composer require diagro/lib_php_chart
包简介
Library for creating ChartJS in PHP.
README 文档
README
Description
Create charts with ChartJS through PHP. You make the chart in PHP code and serialize it to Javascript. In Javascript you create the chart by deserialize the output of the PHP Chart class.
The Manager class holds the graphs and is responsible for rendering.
$("canvas[id^='chart_']").each(function(idx, el) { new Chart( $(el).attr('id'), $.parseJSON(atob($(el).data('chart'))) ); });
If you use Laravel. Simply register the Manager class in the AppServiceProvider.
public function register() { $this->app->singleton('charts', \Diagro\Chart\Manager::class); }
In a blade view:
{{ app('charts')->render('chart_id') }}
Or register a stringable blade like:
Blade::stringable(\Diagro\Chart\Chart::class, function($chart) { return app('charts')->render($chart->id); });
Example:
$chart = new Chart('messages_per_time', Chart::TYPE_BAR); $chart->labels = array_keys($per_datetime); $chart->datasets[0] = new \Diagro\Chart\Datasets\Bar('Aantal per tijdstip'); $chart->datasets[0]->data = array_values($per_datetime); $chart->datasets[0]->background_color = [ new \Diagro\Chart\Color\RGBA(255,99,132,0.2), new \Diagro\Chart\Color\RGBA(54,162,235,0.2) ]; $chart->datasets[0]->border_color = [ new \Diagro\Chart\Color\RGBA(255,99,132,1), new \Diagro\Chart\Color\RGBA(54,162,235,1) ]; $chart->datasets[0]->border_width = 1; $chart->options->plugins->legend->display = false;
统计信息
- 总下载量: 8
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Diagro
- 更新时间: 2022-09-09