我不断收到此错误,但我仍然无法显示Chart.js图表,但我尝试了在互联网上找到的多个代码。Chart.js出现错误:TypeError:t is undefined
下面是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://jsfiddle.net/bd6Lf88a/问题必须在其他地方。划痕;你需要包含最新版本:'https:// cdnjs.cloudflare.com/ajax/libs/Chart.js/2.4.0/Chart.bundle.js' –
是的,现在只是想通了。显然,该CDN上有许多版本不起作用。这一个https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.2.0/Chart.min.js显然也起作用。谢谢。 –