Yii2 Chart is not defined

江枫思渺然 提交于 2020-05-05 21:20:54

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!