我正在使用chart.js,这是我的代码。
<script scr="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.3/Chart.min.js"></script>
var mychart = document.getElementById("myPieChart").getContext('2d');
let round_graph = new chart(mychart, {
type:'doughnut',
data:{
labels:['Billed Samples (Today)','Collected Samples (Today)','Completed Test (Today)','Pending For Validation'],
datasets:[{
lable:'Samples',
data :[
document.getElementById('billed_sample_today').innerHTML,
document.getElementById('bleeded_sample_today').innerHTML,
document.getElementById('completed_sample_today').innerHTML,
document.getElementById('pending_sample_today').innerHTML
],
backgroundColor: ['#4e73df', '#1cc88a', '#36b9cc'],
hoverBackgroundColor: ['#2e59d9', '#17a673', '#2c9faf'],
hoverBorderColor: "rgba(234, 236, 244, 1)",
}]
}
})
我在控制台上收到Uncaught ReferenceError:图表未定义错误。我该如何纠正?
有两件事是错误的:
类应使用大写字母。new chart(mychart, {
-> new Chart
CDN中的库似乎没有返回Chart。尝试他们在其文档中推荐的一种:https://www.chartjs.org/docs/latest/getting-started/