绘制图表后,从图表对象更改Highcharts工具提示格式器 [英] Change Highcharts tooltip formatter from chart Object , after chart is rendered

查看:89
本文介绍了绘制图表后,从图表对象更改Highcharts工具提示格式器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现我可以使用setData更改系列,并且我知道我可以使用.setExtremes修改Max值,但我无法弄清楚如何从图表对象设置工具提示格式器。
如何更新该栏位?
如果我有一个图表对象,我该如何更新其工具提示格式器属性?以及plotOptions工具提示格式化程序如何?



我曾尝试过:

  chart1.tooltip.formatter = function(){return''+ this.series.name +'example:'+ this.y +'example';}; 

但是我在图表定义(用于测试)之后添加了我的工具提示时没有任何更改。
另外,我注意到这个


  console.log(chart1.tooltip.formatter); 

返回undefined,但我不知道为什么。

小提琴让您可以尝试一下。



http://jsfiddle.net/pCuUW/5 /
在此先感谢。

解决方案

您可以使用 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 />');
}

动态更改工具提示格式器| Highchart& Highstock @ jsFiddle

更新
在高图的新版本(5.0.0+)这也可以使用 chart.update()

  chart.update({
tooltip:{
formatter:函数(){
var xyArr = [];
$ .each(this.points,function(){
xyArr.push('Serie:'+ this.series.name +' ,'+'X:'+ this.x +',Y:'+ this.y);
});
return xyArr.join('< br />');
}
}
});

使用chart.update动态更改工具提示格式化程序Highchart& Highstock @ jsFiddle

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?

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.

http://jsfiddle.net/pCuUW/5/ Thanks in advance.

解决方案

You can use chart.tooltip.options.formatter instead, like

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

UPDATE In new (5.0.0+) versions of highcharts, this can also be done using the chart.update() method

  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

这篇关于绘制图表后,从图表对象更改Highcharts工具提示格式器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆