gpt4 book ai didi

javascript - Chart.js:填充两行之间的背景

转载 作者:行者123 更新时间:2023-12-03 00:24:59 24 4
gpt4 key购买 nike

我有两条线的折线图。第一行是静态的,第二行是动态构建的。如果第二行的 y 值高于第一行的 y 值,我需要填充第一行和第二行之间的区域。

我用了Charts.js用于构建图表的库

目前我有下一个结果( Fill between two lines ): enter image description here

预期结果: enter image description here

最佳答案

非常hackish的方式,但它给出了预期的结果:D!

fiddle -> http://jsfiddle.net/Lzo5g01n/28/

var ctx = document.getElementById("myChart").getContext('2d');
var myChart = new Chart(ctx, {
type: 'line',
data: {
labels: ["Yellow", "Blue", "Green", "Orange", "Pink"],
datasets: [{
fill: false,
data: [0, 10, , 10, 0],
backgroundColor: 'black',
borderColor: 'black',
borderWidth: 1
}, {
data: [10, 10, 10, 10, 10],
fill: true,
backgroundColor: 'white',
borderColor: 'black',
borderWidth: 1
}, {
data: [, 10, 18, 10, ],
backgroundColor: 'black',
borderColor: 'black',
borderWidth: 1
}]
},
options: {
scales: {
yAxes: [{
display: false,
ticks: {
beginAtZero: true
}
}],
xAxes: [{
display: false
}]
},
legend: {
display: false
},
tooltips: {
enabled: false
},
elements: {
point: {
radius: 0
}
}
}
});

关于javascript - Chart.js:填充两行之间的背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54132379/

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