javascript-未捕获的TypeError:无法读取未定义的属性’draw’
作者:互联网
for (var i = 0; i < reduced.length; i++) {
var innerdata = [];
for (var j = 0; j < days.length; j++) {
var rev = 0;
_.each(reduced[i].data, function(timerevenueObj) {
var current = new Date(parseInt(timerevenueObj[0]));
var daysweek = days[j];
if (current.toDateString() === daysweek.toDateString()) {
rev = rev + timerevenueObj[1];
}
});
innerdata.push(rev);
}
datasets.push({
label: reduced[i].label,
fillColor: "rgba(220,220,220,0.2)",
strokeColor: "rgba(220,220,220,1)",
pointColor: "rgba(220,220,220,1)",
pointStrokeColor: "#fff",
pointHighlightFill: "#fff",
pointHighlightStroke: "rgba(220,220,220,1)",
data: innerdata
});
}
data.push({
labels: ["May 17","May 18","May 19","May 20","May 21","May 22","May 23","May 24","May 25","May 26","May 27"],
datasets: datasets
});
reduce是具有以下格式的Objects数组:
频道1
CreateTime
Revenue
CreateTime
Revenue
频道2
CreateTime
Revenue
CreateTime
Revenue
数据格式:
尝试显示折线图时出现错误
解决方法:
Chartjs需要一个对象,而不是数组,因此请使用data = {}而不是data.push({}).
标签:chart-js,arrays,javascript 来源: https://codeday.me/bug/20191120/2042562.html