Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Highcharts chart.tooltip.formatter overriding series.tooltip.pointFormatter?

My approach is configuring a chart with a certain tooltip-format:

Highcharts.chart('container', {
    tooltip: {
            formatter: function () { return 'Default Format ...';  }
    },
    ...
}

... and for certain series, i need to specify a modyfied formatter:

series: [{
    data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4],
    tooltip: {
      pointFormatter: function () { return 'Custom Format...'; }
    }
  }, 
  ...
]

So this does not work, because, as i figured out, the chart-tooltip-formatter always overrides the pointFormatter of the series configuration. You can try this here, if you comment out the charts tooltip-configuration.

I would expect a way to set a "default" tooltip-configuration over the formatter-function for the whole chart and the possibility to override this for certain series. Is there a way to do so?

I found a few approaches like this, but i need a more general apporach than if-elseing series names within the formatter function. i also want to be able to modify values, so attributes like 'valueSuffix' dont get me very far.

like image 564
LocalHorst Avatar asked Apr 13 '17 09:04

LocalHorst


1 Answers

I'm not quite sure how this override happens, but as you mention the tooltip.formatter takes precedence. Instead of using tooltip.formatter move the same function to plotOptions.series.tooltip.pointFormatter. This should work as you expect, with the plotOptions pointFormatter being used in general and your series pointFormatter being used in the specific cases.

For example (JSFiddle):

plotOptions: {
    series: {
        tooltip: {
            pointFormatter: function () { return 'Default ' + this.x + '</b> is <b>' + this.y + '</b>';  }
        }
    }
},

series: [{
    data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4],
    tooltip: {
        pointFormatter: function () { return 'Custom Format...'; }
    }
}]
like image 179
Halvor Holsten Strand Avatar answered Jan 03 '23 05:01

Halvor Holsten Strand