我试图将多个图表添加到刀片模板但遗憾的是没有成功。
Laravel版本:5.6 包: https://github.com/fxcosta/laravel-chartjs
$chartjs = app()->chartjs
->name('lineChartTest')
->type('line')
->size(['width' => 400, 'height' => 200])
->labels($date)
->datasets([
[
"label" => "Gesammelte Coins",
'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' => $coins,
]
])
->options([]);
$chartjs2 = app()->chartjs
->name('lineChartTest')
->type('line')
->size(['width' => 400, 'height' => 200])
->labels($date2)
->datasets([
[
"label" => "Gesammelte Coins",
'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' => $coins2,
]
])
->options([]);
return view('vendor/voyager/dashboard', [
'chartjs' => $chartjs,
'chartjs2' => $chartjs2
]);
//blade template
<div style="background:#FFF; margin-top:20px;" class="col-md-6">
{!! $chartjs->render() !!}
</div>
<div style="background:#FFF; margin-top:20px;" class="col-md-6">
{!! $chartjs2->render() !!}
</div>
我可以成功添加一个图表,但是当我尝试添加两个图表时,我得到一张空白图表。
答案 0 :(得分:0)
我认为您需要更改chartjs
的名称属性。
在上面的示例中,您对2个chartjs具有相同的名称。
所以,只需更改名称属性:
并且第一个图表为她命名:lineChartTestOne
$chartjs = app()->chartjs
->name('lineChartTestOne')
->type('line')
->size(['width' => 400, 'height' => 200])
->labels($date)
->datasets([
[
"label" => "Gesammelte Coins",
'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' => $coins,
]
])
->options([]);
并且第二个图表为她命名:lineChartTestTow
$chartjs2 = app()->chartjs
->name('lineChartTestTow')
->type('line')
->size(['width' => 400, 'height' => 200])
->labels($date)
->datasets([
[
"label" => "Gesammelte Coins",
'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' => $coins,
]
])
->options([]);