gpt4 book ai didi

javascript - Chart JS Line Graph multitooltipkey背景颜色问题

转载 作者:行者123 更新时间:2023-12-03 05:52:21 25 4
gpt4 key购买 nike

我有关于 Chart.js 的问题。我使用的是带有 2 组数据(2 条线)的折线图,当我将鼠标悬停在数据上时,它会显示“图例”。图例中有 2 个可以着色的盒子。我可以毫无问题地更改盒子的背景颜色,但是当我更改颜色时,它会应用于两个盒子。如何单独设置盒子的颜色?谢谢。

    <canvas
class="ex-line-graph"
width="1200" height="1200"
data-chart="line"
data-scale-start-value="0"
data-scale-step-width ="100"
data-scale-steps ="4"
data-point-fill-color = "RGBA( 255,28,221,.3)"
data-scale-line-color="transparent"
data-scale-grid-line-color="rgba(255,255,255,.05)"
data-scale-font-color="#a2a2a2"
data-labels=" ['April','May','June','July','August','September','October','November','December ','January','February','March']"
data-value="[{ fillColor: 'RGBA( 28,168,221,.3)', strokeColor:
'#1CA8DD', label:'Data', data: [151, 154, 173, 169, 176,161,0,0,0,0,0,0]}, {fillColor: 'RGBA(37,40,48,.0)', strokeColor: 'rgba(255,255,255,1)', label :'Target', data: [200, 200,200,200,200, 200,200,200,200, 200,200,200] }]">
</canvas>

最佳答案

如果我遵循正确的话,这是一个由两部分组成的答案:

1.- 指定数据集的颜色:

var data = {
labels: ["January", "February", "March", "April", "May"],
datasets: [{
label: "Series A",
data: [10, 30, 20, 40, 10],
borderColor: "rgba(0,0,255,0.8)",
backgroundColor:"rgba(0,0,255,0.5)"
}, {
label: "Series B",
data: [25, 40, 10, 40, 30],
borderColor: "rgba(255,0,0,0.8)",
backgroundColor:"rgba(255,0,0,0.5)"
}]
};

并启用选项对象上的工具提示(注意模式标签):

var options = {
tooltips: {
enabled: true,
mode: 'label'
},
legend: {
display: true,
}
};

结果:

Chart.js label tooltips

代码笔:

Codepen - Chart.js Multiline Tooltip labels

关于javascript - Chart JS Line Graph multitooltipkey背景颜色问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40094194/

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