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

问题描述

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



我曾尝试过:

  

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



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

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

UPDATEIn 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工具提示格式器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-15 00:58