问题
I am trying to show some data on the chart while using Yii2
. I have installed Yii2 Chart JS via the composer. Below is the code is taken from the documentation
use practically\chartjs\Chart;
Chart::widget([
'type' => Chart::TYPE_BAR,
'datasets' => [
[
'data' => [
'Label 1' => 10,
'Label 2' => 20,
'Label 3' => 30
]
]
]
]);
Now when I refreshed this page I not seeing any chart. But in inspect->console
I am getting an error
Uncaught ReferenceError: Chart is not defined
Update 1
Here is my composer.lock file
I have looked into this issue and found some solutions but still unable to perform the task.
Any help would be highly appreciated.
回答1:
To display chart you must echo
result of widget
echo Chart::widget([
'type' => Chart::TYPE_BAR,
'datasets' => [
[
'data' => [
'Label 1' => 10,
'Label 2' => 20,
'Label 3' => 30
]
]
]
]);
来源:https://stackoverflow.com/questions/61255144/yii2-chart-is-not-defined