如何解决如何在 Canvasjs 多折线图中更改索引和工具提示的颜色?
所以我正在处理我的项目,该项目获取数据并将其显示在图表上我是 JS 新手,我从未使用过 Canvasjs。我想更改索引和工具提示的颜色,如下图所示我能够更改线条颜色,但它不会更改索引和工具提示中的颜色,当我将鼠标悬停在一条线上时,它会显示标记上的先前颜色。我希望我说得容易理解。
我想改变什么
这是我的 .js 代码
var chart = new CanvasJS.Chart("chartContainer",{
animationEnabled: true,backgroundColor: "transparent",labelFontColor: '#f5f6fa',title:{
text: ""
},axisX: {
valueFormatString: "DD MMM,YY",lineColor: "#f5f6fa",fontFamily: "'Roboto',sans-serif",labelFontColor: "#f5f6fa",},axisY: {
title: "Temperature (in °C)",suffix: " °C",legend:{
cursor: "pointer",fontSize: 16,fontColor: "#f5f6fa",itemclick: toggleDataSeries
},toolTip:{
shared: true
},data: [{
name: "Myrtle Beach",type: "line",markerSize: 0,lineColor: "#2196f3",showInLegend: true,yValueFormatString: "#0.## °C",dataPoints: [
{ x: new Date(2017,6,24),y: 31 },{ x: new Date(2017,25),26),y: 29 },27),28),29),y: 30 },30),y: 29 }
]
},{
name: "Martha Vineyard",lineColor: "#f44336",y: 20 },y: 25 },y: 25 }
]
},{
name: "Nantucket",lineColor: "#ffca28",y: 22 },y: 19 },y: 23 },y: 24 },y: 23 }
]
}]
});
chart.render();
function toggleDataSeries(e){
if (typeof(e.dataSeries.visible) === "undefined" || e.dataSeries.visible) {
e.dataSeries.visible = false;
}
else{
e.dataSeries.visible = true;
}
chart.render();
}
}```
解决方法
我不敢相信这个答案如此简单,只需替换
这个:-
lineColor
到:-
color
如果您希望线条的颜色相同,图例标记和工具提示中使用 color
而不是 lineColor
。
因为 lineColor
只会改变图表中线条的颜色。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。