将鼠标悬停在列栏上时,工具提示应显示两种颜色,分别为OKR for the year和Year to date,但显示的颜色相同。我正在使用这个脚本。
tooltip: {
formatter: function() {
let xAxisValue = this.point.name;
let yAxisValue = this.y;
let xAxisName = this.series.name;
if(hasMultipleCols){
if(typeof chartArrayData[1] != 'undefined') {
yAxisValue = chartArrayData[1].data[this.point.index]; // this.point.name == undefined ? this.point.y : this.point.name
xAxisValue = chartArrayData[0].data[this.point.index];
xAxisName = chartArrayData[0].name;
yAxisName = chartArrayData[1].name;
}
}
return `<span style="color:${this.color}">●</span> ${yAxisName }: <b>${ yAxisValue}</b><br/><span style="color:${this.color}">●</span> ${xAxisName}: <b>${xAxisValue }</b>`;
},
}
请附件
请引导我。
谢谢
2条答案
按热度按时间u1ehiz5o1#
最简单的方法是启用工具提示的
shared
选项:但是,如果您想保留自定义格式,可以使用以下格式化程序函数:
现场演示:http://jsfiddle.net/BlackLabel/tf6jc5op/
API引用:
https://api.highcharts.com/highcharts/tooltip.formatter
https://api.highcharts.com/highcharts/tooltip.shared
nimxete22#
将颜色更改为静态变量,如果颜色仍然与bar相同,也许您应该检查
colorByPoint
属性。如果是true
,工具提示的颜色将设置为点的颜色。两个
this.color
目标指向同一点,因此将第二个更改为另一个颜色。方案一:添加一个
shared: true
属性,实现条间信息共享。像这样👇
方案2:通过以下方式获得颜色:
this.point.series.xAxis.series[1].color