javascript 呈现图表后,从图表对象更改 Highcharts 工具提示格式化程序
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13479476/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Change Highcharts tooltip formatter from chart Object , after chart is rendered
提问by Romina12345
I have found that I can change series with setData, and I know I can modify Max values with .setExtremes , but I cannot figure out how to set the tooltip formatter from the chart object. How do I update that field ? If i have a chart object , how do I update its tooltip formatter property ? and How about the plotOptions tooltip formatter?
我发现我可以使用 setData 更改系列,并且我知道我可以使用 .setExtremes 修改最大值,但我无法弄清楚如何从图表对象设置工具提示格式化程序。如何更新该字段?如果我有一个图表对象,我该如何更新它的工具提示格式化程序属性?以及 plotOptions 工具提示格式化程序如何?
What I have tried :
我尝试过的:
chart1.tooltip.formatter = function() {return ''+this.series.name +'example: '+ this.y +'example';};
But nothing changed in my tooltips when i added that after the chart definition (for testing). Also, I noted that this
但是当我在图表定义(用于测试)之后添加它时,我的工具提示没有任何变化。另外,我注意到这
console.log (chart1.tooltip.formatter);
returns undefined, but I don't know why.
返回未定义,但我不知道为什么。
Fiddle so you can try it out.
Fiddle 所以你可以尝试一下。
http://jsfiddle.net/pCuUW/5/Thanks in advance.
回答by Jugal Thakkar
You can use chart.tooltip.options.formatter
instead, like
您可以chart.tooltip.options.formatter
改用,例如
chart.tooltip.options.formatter = function() {
var xyArr=[];
$.each(this.points,function(){
xyArr.push('Serie: ' + this.series.name + ', ' +'X: ' + this.x + ', Y: ' +this.y);
});
return xyArr.join('<br/>');
}
Changing tooltip formatter dynamically | Highchart & Highstock @ jsFiddle
动态更改工具提示格式化程序 | Highchart & Highstock @ jsFiddle
UPDATEIn new (5.0.0+) versions of highcharts, this can also be done using the chart.update()
method
更新在新的 (5.0.0+) 版本的 highcharts 中,这也可以使用chart.update()
方法来完成
chart.update({
tooltip: {
formatter: function() {
var xyArr = [];
$.each(this.points, function() {
xyArr.push('Serie: ' + this.series.name + ', ' + 'X: ' + this.x + ', Y: ' + this.y);
});
return xyArr.join('<br/>');
}
}
});
Changing tooltip formatter dynamically with chart.update | Highchart & Highstock @ jsFiddle
使用 chart.update 动态更改工具提示格式化程序 | Highchart & Highstock @ jsFiddle