gpt4 book ai didi

javascript - Chart Js 使用图形线条样式更新图形的图例框

转载 作者:行者123 更新时间:2023-11-30 14:55:54 25 4
gpt4 key购买 nike

我想用图形线条样式更新图形的图例框。

enter image description here实际消费enter image description here平均使用

enter image description here

下面是我的代码,但图例标签图像没有更新。谁能帮帮我?

var ctx = document.getElementById("myChart");
this.myChart = new Chart(ctx, {
type: 'line',
data: {
labels: ["Jan", "Blue", "Yellow", "Green", "Purple", "Orange"],
datasets: [{
label: 'Actual Consumption',
data:[24, 49, 6, 7, 21, 6],
backgroundColor: [
'rgba(225,225,225,0)'
],
borderColor: [
'rgba(53,91,183,1)'
],
borderWidth: 2.2,
pointStyle: 'circle',
},{
label: 'Average Use ',
data:[4, 12, 2, 17, 22, 2],
backgroundColor: [
'rgba(225,225,225,0)'
],
borderColor: [
'rgba(230,104,38,1)'

],
borderWidth: 2.2,
pointStyle: 'rect',

},{
label: 'Total Use',
data:this.data,
backgroundColor: [
'rgba(225,225,225,0)'
],
borderColor: [
'rgba(148,148,148,1)'
] ,
borderWidth: 2.2,
pointStyle: 'triangle',

}]
},
options: {
scales: {
yAxes: [{
ticks: {
beginAtZero:true
}
}]
},
**legend: {
cursor : "pointer",
useLineStyle: true,
labels: {
fontColor: '#000000'
}
}**
}
});

最佳答案

有一个名为“usePointStyle”的图例选项,它应该使图例样式与图形点的样式相匹配。

legend: {
labels: {
usePointStyle: true
}
}

如果这不能解决您的问题,您可能必须使用“legendCallback”来创建自定义 HTML 图例。

关于javascript - Chart Js 使用图形线条样式更新图形的图例框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47286898/

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