【发布时间】:2019-02-10 11:10:14
【问题描述】:
我正在通过 ajax 获取 ChartJs 图表的数据和标签,并以此创建一个数组。
当我制作 console.log 时,数组看起来可以正常工作,但图表没有标签也没有数据。
我在这里找到了this 的问题,但并没有解决问题。
这是我的 chartJs 代码:
config = {
type: 'bar',
data: {
labels: labels,
datasets: [{
label: "Aufrufe",
data: dataarray,
backgroundColor: 'rgba(0, 188, 212, 0.8)'
}]
},
options: {
responsive: true,
legend: false
}
}
以及我从 console.log 获得的数组:
这就是我创建数组的方式:
/* create a labels array */
while(year !== (new Date).getFullYear() || month !== enddate) {
console.log(year, month);
labels.push(month + " " + year);
month++;
if(month === 13) {
year++;
month = 1;
}
}
但图表只是一个空图表...
【问题讨论】:
标签: javascript chart.js