【发布时间】:2019-11-14 22:55:18
【问题描述】:
我有不同月份的数据,如下所示
一月:[1,5,3]
二月:[10,5]
三月:[4,8]
四月:[7]
五月:[3,1,5,0,7]
我想生成如下条形图
现在,我有以下代码,我想知道如何生成如上图所示的条形图。
new Chart(document.getElementById("bar-chart"), {
type: 'bar',
data: {
labels: ['Jan','Feb','Mar','Apr','May'],
datasets: [{
data: [1,5,3],
label: 'Jan',
backgroundColor: "#3e95cd",
}
, {
data: [10,5],
label: 'Feb',
backgroundColor: "#8e5ea2",
}, {
data: [4,8],
label: 'Mar',
backgroundColor: "#4287f5",
}
, {
data: [7],
label: 'Apr',
backgroundColor: "#23ebbc",
}
, {
data: [3,1,5,0,7],
label: 'May',
backgroundColor: "#e63057",
}
]
},
options: {
title: {
display: true,
text: 'This is title'
},
backgroundColor:'#cfcfcf',
scales: {
xAxes: [{ stacked: true }],
yAxes: [{ stacked: true }]
}
}
});
谢谢
【问题讨论】:
标签: javascript charts chart.js bar-chart stacked-chart