gpt4 book ai didi

javascript - Chart.js 移除堆叠

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:21:36 24 4
gpt4 key购买 nike

我有一个堆积条形图和两个折线图。第二个折线图堆叠在第一个折线图的顶部,但我不希望出现这种情况。

我尝试过将堆栈模式显式设置为 false ,但此选项未被执行。

            ...
type: 'line',
label: 'lineChart1',
data: lineData1,
borderWidth: 1,
fill: false,
options: {
legend: {
display: false
},
scales: {
xAxes: [{
stacked: false,
}],
yAxes: [{
stacked: false
}]
}
}
}
...

最佳答案

这是一个示例,它配置了一个包含 2 个堆积条和 2 个非堆积线的图表。我认为您在折线图上堆叠的原因是您没有在条形图中设置 stacked 选项来为它们提供堆叠 ID。

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.green,
borderWidth: 2,
fill: false,
data: [5, 3, 4, 10, 8, 9, 2]
}, {
type: 'line',
label: 'Dataset 2',
borderColor: window.chartColors.orange,
borderWidth: 2,
fill: false,
data: [8, 5, 2, 8, 7, 2, 6]
}, {
type: 'bar',
label: 'Dataset 3',
backgroundColor: window.chartColors.red,
stack: 'Stack 0',
data: [2, 4, 1, 3, 7, 3, 6],
borderColor: 'white',
borderWidth: 2
}, {
type: 'bar',
label: 'Dataset 4',
backgroundColor: window.chartColors.blue,
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这显示了它的样子。

关于javascript - Chart.js 移除堆叠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42959474/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com