gpt4 book ai didi

javascript - 未捕获的类型错误 : Chart is not a constructor when using Chart. js

转载 作者:行者123 更新时间:2023-11-30 11:42:56 26 4
gpt4 key购买 nike

我正在处理我的第一个 Cordova 项目并尝试使用 Chart.js。文档指出应该像这样包含 Chart.js:

<script src="Chart.js"></script>
<script>
var myChart = new Chart({...})
</script>

我使用 Bower 安装了该库,它现在位于 www/lib/chart.js 下。 Chrome 给我 Failed to load resource: the server responded with a status of 404 当我加载 Chart.jslib/chart.js.

当我加载 lib/chart.js/src/chart.js 时,我得到一个不同的错误,在这一行中显示 Uncaught TypeError: Chart is not a constructor:

  var ctx = document.getElementById("myChart");
var myChart = new Chart(ctx, { //...

这是文件 chart.js 中的内容:

var Chart = require('./core/core.js')();

require('./core/core.helpers')(Chart);
// ...

window.Chart = module.exports = Chart;

这是正确的 chart.js 文件吗?

最佳答案

我认为您使用的 chart.js 有错误
试试这个:

<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.4.0/Chart.min.js"></script>

关于javascript - 未捕获的类型错误 : Chart is not a constructor when using Chart. js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41967063/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com