我正在迁移到chart.js 4.4.1,在之前的版本(2.9.4)中,我能够用所附图像中的 colored颜色 填充空白.
在最新的版本中,我可以使用不透明来接近,但它并不完全相同: 4.4.1 sample img个
对如何实现这一点有什么 idea 吗?我使用的是非模块的JavaScript chartjs文件.
请参阅下面的测试代码.
<canvas id="my-chart"></canvas>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/4.4.1/chart.umd.js"></script>
<script>
let labels = [];
for (let year=2000; year <= 2010; year++) {
labels.push(year);
}
const config = {
data: {
labels: labels,
datasets: [
{
type: "bar",
label: "Product",
data: [1331320,2851137,5952127,6607851,11068289,12059067,12117998,11827962,16582836,20184478,23915606],
backgroundColor: "#bec38f",
order: 1
},
{
backgroundColor: "rgba(151,156,106,0.5)",// "#979c6a",
borderColor: "#826f68",
borderWidth: 3,
data: [1242306,2442693,5070218,5502960,8572948,7722718,6916448,7196356,10429229,12544283,15149568],
label: "Benchmark",
type: "line",
fill: true,
pointBackgroundColor: "#ffffff",
pointRadius: 5,
order: 0
}
]
},
options: {
scales: {
x: {
grid: {
display: false
}
},
y: {
stacked: true,
scaleLabel: {
display: false
},
ticks: {
callback: function(value, index, ticks) {
return ("$" + (value/1000000));
}
}
}
},
plugins: {
tooltip: {
intersect: true,
callbacks: {
label: function(context) {
return ("$" + context.parsed.y.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","));
}
}
}
}
}
};
new Chart(document.getElementById("my-chart"), config);
</script>