Change Highcharts tooltip formatter from chart Object , after chart is rendered

佐手、 提交于 2019-12-22 03:49:22

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/13479476/change-highcharts-tooltip-formatter-from-chart-object-after-chart-is-rendered

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!