【发布时间】:2017-12-22 21:54:07
【问题描述】:
我正在尝试使用 chartjs 创建堆叠条形图。我的时间序列在时间上存在差异,这意味着一些序列可以在一段时间内有价值,而其他序列则没有。出于这个原因,我选择直接将 x 值包含在数据集中,而不是作为标签数组,但图表无法正确呈现。
这是我的代码:
var config = {
type:'bar',
data:{
datasets:datasets
},
options: {
responsive: true,
title:{
display:true,
text:"MyChart"
},
tooltips: {
mode: 'index'
},
hover: {
mode: 'index'
},
legend: {
position: 'bottom'
},
elements: { point: { radius: 0 }},
scales: {
xAxes: [{
stacked: true,
type: 'time',
time: {
unit: 'minutes',
unitStepSize: 5,
displayFormats:{
minutes:'HH:mm'
}
},
scaleLabel: {
display: true,
labelString: 'Date'
}
}],
yAxes: [{
stacked:true,
scaleLabel: {
display: true,
labelString: 'Resources Consumed'
}
}]
}
}
};
var ctx = document.getElementById('session-sql-activity').getContext("2d");
ctx.canvas.height = 300;
ctx.canvas.width = 800;
new Chart(ctx,config);
我认为问题在于 x 轴堆叠。
这是一个说明问题的 JSFiddle。
【问题讨论】:
标签: chart.js