var bar_ctx = document.getElementById('bar-chart').getContext('2d');
var bar_chart = new Chart(bar_ctx, {
type: 'bar',
data: {
labels: ["1", "2", "3", "4", "5", "6"],
datasets: [{
label: 'test0',
data: [3, 4, 7, 3, 6, 2],
backgroundColor: 'deepskyblue',
}, {
label: 'test1',
data: [2, 9, 3, 3, 4, 8],
backgroundColor: 'skyblue'
},
{
label: 'test2',
data: [2, 9, 3, 3, 4, 8],
backgroundColor: 'powderblue'
}
]
},
options: {
legend: {
display: false
},
scales: {
yAxes: [{
stacked: true,
ticks: {
beginAtZero: true
}
}],
xAxes: [{
stacked: true,
}]
}
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.5.0/Chart.bundle.min.js"></script>
<canvas id="bar-chart"></canvas>
是的,找到了答案前面卻忘了張貼在這裏。無論如何感謝:D –
對於任何有興趣的人,這裏是上述代碼的JSFiddle:https://jsfiddle.net/xk7gj2xy/ –