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

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

问题描述

我试图在使用 Yii2 时在图表上显示一些数据.我已经通过 Composer 安装了 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 practicallychartjsChart;

Chart::widget([
    'type' => Chart::TYPE_BAR,
    'datasets' => [
        [
            'data' => [
                'Label 1' => 10,
                'Label 2' => 20,
                'Label 3' => 30
            ]
        ]
    ]
]);

现在,当我刷新此页面时,我看不到任何图表.但是在 inspect->console 中我收到一个错误

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

更新 1

这是我的 composer.lock 文件

我已经调查了这个问题并找到了一些解决方案,但仍然无法执行任务.

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

任何帮助将不胜感激.

推荐答案

要显示图表你必须echowidget的结果

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天全站免登陆