Chart.js-未捕获的ReferenceError:未定义图表

问题描述 投票:0回答:1

我正在使用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:图表未定义错误。我该如何纠正?

javascript chart.js
1个回答
0
投票

有两件事是错误的:

  1. 类应使用大写字母。new chart(mychart, {-> new Chart

  2. CDN中的库似乎没有返回Chart。尝试他们在其文档中推荐的一种:https://www.chartjs.org/docs/latest/getting-started/

© www.soinside.com 2019 - 2024. All rights reserved.