我正在使用发现的here软件包在我的laravel项目上使用chartjs,我按照说明进行安装,并尝试将示例加载到刀片文件中。问题是,什么都没有显示。在下面的示例代码中,有没有人有使用此程序包的经验,可以指出正确的方向?
我安装它的方式是:
composer require fx3costa/laravelchartjs
added Fx3costa\LaravelChartJs\Providers\ChartjsServiceProvider::class to Providers
npm install chart.js --save
示例方法。
private function createchart(){
$chartjs = app()->chartjs
->name('lineChartTest')
->type('line')
->size(['width' => 400, 'height' => 200])
->labels(['January', 'February', 'March', 'April', 'May', 'June', 'July'])
->datasets([
[
"label" => "My First dataset",
'backgroundColor' => "rgba(38, 185, 154, 0.31)",
'borderColor' => "rgba(38, 185, 154, 0.7)",
"pointBorderColor" => "rgba(38, 185, 154, 0.7)",
"pointBackgroundColor" => "rgba(38, 185, 154, 0.7)",
"pointHoverBackgroundColor" => "#fff",
"pointHoverBorderColor" => "rgba(220,220,220,1)",
'data' => [65, 59, 80, 81, 56, 55, 40],
],
[
"label" => "My Second dataset",
'backgroundColor' => "rgba(38, 185, 154, 0.31)",
'borderColor' => "rgba(38, 185, 154, 0.7)",
"pointBorderColor" => "rgba(38, 185, 154, 0.7)",
"pointBackgroundColor" => "rgba(38, 185, 154, 0.7)",
"pointHoverBackgroundColor" => "#fff",
"pointHoverBorderColor" => "rgba(220,220,220,1)",
'data' => [12, 33, 44, 44, 55, 23, 40],
]
])
->options([]);
return $chartjs;
刀片文件:
<div style="width:75%;">
{!! $chartjs->render() !!}
</div>
答案 0 :(得分:1)
问题在于命令npm install chart.js --save
仅安装chartjs libray(在/ node_modules目录中),您还需要将其与项目集成,例如,将脚本标记放置在<head>
中:
<script src="path/to/chartjs/dist/Chart.js"></script>