未定义Yii2图表 [英] Yii2 Chart is not defined

查看:79
本文介绍了未定义Yii2图表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 Yii2 在图表上显示一些数据。我已经通过作曲家安装了 Yii2 Chart JS 。下面的代码摘自文档

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
            ]
        ]
    ]
]);

现在,当我刷新此页面时,没有看到任何图表。但是在 inspect->控制台中出现错误

Now when I refreshed this page I not seeing any chart. But in inspect->console I am getting an error


Uncaught ReferenceError:图表未定义

Uncaught ReferenceError: Chart is not defined

更新1

这是我的 composer.lock 文件

我调查了此问题,找到了一些解决方案,但仍然无法执行任务。

I have looked into this issue and found some solutions but still unable to perform the task.

任何帮助将不胜感激。

Any help would be highly appreciated.

推荐答案

要显示图表,您必须 echo 小部件结果

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
            ]
        ]
    ]
]);

这篇关于未定义Yii2图表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆