我可能会误解你正在尝试做的事情,但可以在同一轴上创建一个堆叠的条形图,其中包含未堆叠的折线图组合。
下面是一个示例配置,显示如何操作。
var myChart = new Chart(ctx, {
type: 'bar',
data: {
labels: ["January", "February", "March", "April", "May", "June", "July"],
datasets: [{
type: 'line',
label: 'Dataset 1',
borderColor: window.chartColors.blue,
borderWidth: 2,
fill: false,
data: [5, 3, 4, 10, 8, 9, 2]
}, {
type: 'bar',
label: 'Dataset 2',
backgroundColor: window.chartColors.red,
stack: 'Stack 0',
data: [2, 4, 1, 3, 7, 3, 6],
borderColor: 'white',
borderWidth: 2
}, {
type: 'bar',
label: 'Dataset 3',
backgroundColor: window.chartColors.green,
stack: 'Stack 0',
data: [7, 2, 4, 5, 6, 4, 2]
}]
},
options: {
responsive: true,
title: {
display: true,
text: 'Chart.js Stacked Bar and Unstacked Line Combo Chart'
},
tooltips: {
mode: 'index',
intersect: true
},
scales: {
xAxes: [{
stacked: true,
}]
}
}
});
下面是一个工作codepen example以及。
谢谢!我不知道你可以这样组合堆栈(新功能)。这解决了我的问题! –
问题是如果你添加第二行然后那些行将堆栈不? –