我试图在我的程序中使用Chart.js
。我在公共托管网站上托管了我的php和JavaScript文件。当我尝试运行图表功能时,我收到以下错误:
未捕获的TypeError:无法读取属性'数据集'未定义"。请找到以下代码。
<head>
<title>Operation Details</title>
<script src="../Chart.js"></script>
</head>
var barChartData = {
labels : [month1,month2,month3,month4,month5,month6,month7,month8,month9,month10,month11,month12],
datasets : [
{
label: "My First dataset", fillColor : "rgba(192,192,192,0.5)", strokeColor : "rgba(192,192,192,0.8)", highlightFill: "rgba(192,192,192,0.75)", highlightStroke: "rgba(192,192,192,1)",
data : [avg1[temp[i]],avg2[temp[i]]]
}
]
}
//...
window.onload = function(){
var ctx = document.getElementById("canvas").getContext("2d");
window.myBar = new Chart(ctx).Bar(barChartData, {
responsive: true
});
//...
}
chart.js之:
helpers.each(data.datasets,function(dataset,datasetIndex){
var datasetObject = {
//...
我对JavaScript和这个论坛都是全新的。如果出现问题,请就此提出建议。