laravel5.5通过charts实现画图功能
一、安装
1.下载
composer require consoletvs/charts:5.*
2.添加service provider和重命名
在config/app.php
中添加
'providers' => [
....
ConsoleTVs\Charts\ChartsServiceProvider::class,
],
同时在alias中添加
'aliases' => [
....
'Charts' => ConsoleTVs\Charts\Facades\Charts::class,
]
最后
php artisan vendor:publish
二、使用方法
1.添加路由
Route::get('/test2', 'CunliangController@test2')->name('test2');
2.控制器
public function test2()
{
$data = Cunliang::where("file_type", "O")->orderBy('created_at','desc')
->take(7)
->get();
$chart = Charts::create('bar', 'highcharts')
->title('O域数据最近七天更新情况')
->elementLabel('大小(M)')
->labels($data->pluck('created_at'))
->values($data->pluck('space_size'))
->responsive(false);
return view('cunliang.test2',['chart' => $chart]);
}
3.页面展示
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>My Charts</title>
{!! Charts::styles() !!}
</head>
<body>
<!-- Main Application (Can be VueJS or other JS framework) -->
<div class="app">
<center>
{!! $chart->html() !!}
</center>
</div>
<!-- End Of Main Application -->
{!! Charts::scripts() !!}
{!! $chart->script() !!}
</body>
</html>
不过此方法数据显示延迟比较大