【发布时间】:2019-02-28 10:41:27
【问题描述】:
在条形时间图中添加数据有两种方式
当我们在标签中添加日期并将 y 作为数据传递给数据集时
直接在数据集中添加为 (x,y) 对
第一个完美运行,而第二个不渲染任何东西
var barChartData = {
labels: [moment().add(1, 'd').toDate(), moment().add(2, 'd').toDate(), moment().add(3, 'd').toDate(), moment().add(4, 'd').toDate(), moment().add(5, 'd').toDate(), moment().add(6, 'd').toDate(), moment().add(7, 'd').toDate()],
datasets: [{
label: 'Dataset 1',
backgroundColor: window.chartColors.red,
data: [
Math.random()*100,
Math.random()*100,
Math.random()*100,
Math.random()*100,
Math.random()*100,
Math.random()*100,
Math.random()*100
]
}]
}
var barChartData = {
datasets: [{
label: 'Dataset 1',
backgroundColor: window.chartColors.red,
data: [
{ x: moment().add(1, 'd').toDate(), y: Math.random()*100 },
{ x: moment().add(2, 'd').toDate(), y: Math.random()*100 },
{ x: moment().add(3, 'd').toDate(), y: Math.random()*100 },
{ x: moment().add(4, 'd').toDate(), y: Math.random()*100 },
{ x: moment().add(5, 'd').toDate(), y: Math.random()*100 },
{ x: moment().add(6, 'd').toDate(), y: Math.random()*100 },
{ x: moment().add(7, 'd').toDate(), y: Math.random()*100 },
]
}]
};
是我做错了什么还是一个错误?
【问题讨论】:
标签: javascript chart.js bar-chart