如何将Chart.js添加到Moodle中的自定义插件中?

发布于 2025-01-27 18:21:39 字数 1063 浏览 3 评论 0原文

我正在创建Moodle中的自定义插件,并且我成功地集成了 Chart.js.js 。当缓存被禁用时,它可以在我的开发环境中完美工作。但是,当我打开缓存时,请在控制台中出现以下错误。

​> amd/build/mql.min.js 。

以下是我的代码。

requirejs.config({
    paths: {
        "chartjs": "https://cdn.jsdelivr.net/npm/[email protected]/dist/chart.min"
    }
});

define(
[
    'jquery',
    'core/str',
    'core/ajax',
    'core/templates',
    'jqueryui',
    'core/modal_factory',
    'core/modal_events',
    'chartjs'
],
function (
    $,
    Str,
    ajax,
    templates,
    jqui,
    ModalFactory,
    ModalEvents,
    Chart
){});

我在做什么错?我该如何解决?

I am creating a custom plugin in Moodle and I have successfully integrated Chart.js. It works perfectly in my development environment when the cache is disabled. But when I turn on my cache, the below error appears in the console.

Enter image description here

Enter image description here

local_mql is my custom plugin and the JavaScript file is added under amd/src/mql.js and the minified version is under amd/build/mql.min.js.

Below is my code.

requirejs.config({
    paths: {
        "chartjs": "https://cdn.jsdelivr.net/npm/[email protected]/dist/chart.min"
    }
});

define(
[
    'jquery',
    'core/str',
    'core/ajax',
    'core/templates',
    'jqueryui',
    'core/modal_factory',
    'core/modal_events',
    'chartjs'
],
function (
    $,
    Str,
    ajax,
    templates,
    jqui,
    ModalFactory,
    ModalEvents,
    Chart
){});

What am I doing wrong? And how do I fix this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

暮年慕年 2025-02-03 18:21:39

使用:

"chartjs": "https://cdn.jsdelivr.net/npm/[email protected]/dist/chart.min"

看来您的道路是错误的。
您缺少文件扩展名。

"chartjs": "https://cdn.jsdelivr.net/npm/[email protected]/dist/chart.min.js"

Use:

"chartjs": "https://cdn.jsdelivr.net/npm/[email protected]/dist/chart.min"

It seems your path is wrong.
You are missing the file extension.

"chartjs": "https://cdn.jsdelivr.net/npm/[email protected]/dist/chart.min.js"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文