编程语言
首页 > 编程语言> > javascript-Chart.js错误:TypeError:t未定义

javascript-Chart.js错误:TypeError:t未定义

作者:互联网

我一直收到此错误,尽管我尝试了在互联网上找到的倍数代码,但仍无法显示Chart.js图表​​.

这是HTML的相关部分:

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

<body>
    <canvas id = "myChart"></canvas>
    ...
</body>

这是javascript:

var ctx = document.getElementById("myChart");
var myChart = new Chart(ctx, {
    type: 'bar',
    data: {
        labels: ["Red", "Blue", "Yellow", "Green", "Purple", "Orange"],
        datasets: [{
            label: '# of Votes',
            data: [12, 19, 3, 5, 2, 3],
            backgroundColor: [
                'rgba(255, 99, 132, 0.2)',
                'rgba(54, 162, 235, 0.2)',
                'rgba(255, 206, 86, 0.2)',
                'rgba(75, 192, 192, 0.2)',
                'rgba(153, 102, 255, 0.2)',
                'rgba(255, 159, 64, 0.2)'
            ],
            borderColor: [
                'rgba(255,99,132,1)',
                'rgba(54, 162, 235, 1)',
                'rgba(255, 206, 86, 1)',
                'rgba(75, 192, 192, 1)',
                'rgba(153, 102, 255, 1)',
                'rgba(255, 159, 64, 1)'
            ],
            borderWidth: 1
        }]
    },
    options: {
        scales: {
            yAxes: [{
                ticks: {
                    beginAtZero:true
                }
            }]
        }
    }
});

我在这里找到该示例:http://www.chartjs.org/docs/

我在控制台中收到此错误:

TypeError: t is undefined

有人可以帮忙吗?谢谢.

解决方法:

解决了,显然我正在使用的脚本链接已被修复.将其更改为https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.4.0/Chart.min.js,它可以正常工作.参见Chris G的评论.

标签:chart-js,javascript
来源: https://codeday.me/bug/20191112/2023826.html