Highcharts 如何在plotoptions mouseover事件中同时显示序列值
使用工具提示格式化程序,我们可以同时显示序列名称和值,但使用plotoptions事件鼠标执行相同操作时,我无法获取序列名称和值 工具提示: 打印选项:Highcharts 如何在plotoptions mouseover事件中同时显示序列值,highcharts,Highcharts,使用工具提示格式化程序,我们可以同时显示序列名称和值,但使用plotoptions事件鼠标执行相同操作时,我无法获取序列名称和值 工具提示: 打印选项: 在mouseover mouseOver: function () { console.log(this); var series = this.series.chart.series,
在
mouseover
mouseOver: function () {
console.log(this);
var series = this.series.chart.series,
x = this.x,
y = this.y,
output = 'x: ' + x + 'y: ' + Highcharts.numberFormat(Math.abs(y));
//loop each serie
$.each(series, function (i, e) {
output += ' Category: ' + this.name;
if(i>0) {
$.each(series[i].data,function(j,point){
if(point.x === x) {
output += ' y: ' + Highcharts.numberFormat(Math.abs(y));
}
});
}
});
$reporting.html(output);
}
}
},
请查看console,它返回许多错误,因为我看到这个.series.name未定义。更重要的是,在这个对象上循环的目的是什么?是的,如果我移除循环,它就可以正常工作;我能得到这个系列的名字。但是如何获取序列名称及其值呢?在这个.series.chart.series中,您拥有所有序列。然后可以循环此对象。如果使用this.series.chart.series,我将无法获取图表系列名称或系列值!因为值不是串联的,而是点。更重要的是,x在串联的循环中,指的是串联,而不是点。所以,您需要添加变量,它将保留点值,并且在循环中只打印变量。
mouseOver: function () {
console.log(this);
var series = this.series.chart.series,
x = this.x,
y = this.y,
output = 'x: ' + x + 'y: ' + Highcharts.numberFormat(Math.abs(y));
//loop each serie
$.each(series, function (i, e) {
output += ' Category: ' + this.name;
if(i>0) {
$.each(series[i].data,function(j,point){
if(point.x === x) {
output += ' y: ' + Highcharts.numberFormat(Math.abs(y));
}
});
}
});
$reporting.html(output);
}
}
},