Highcharts: conditional tooltip based on multiple series names (logical OR operator)

You can usually customize the tooltip format based on the series name in highchart using the following code type:

tooltip: { formatter: function() { return ''+ this.x +': '+ this.y + (this.series.name == 'Recovered' ? '%' : ''); } } 

Above is said in the last line, if this is the name of the series โ€œRestoredโ€, then add โ€œ%โ€, otherwise do not add anything.

However, I want my two series to have% not only one, so I want to add an OR operator, something like

  tooltip: { formatter: function() { return ''+ this.x +': '+ this.y + (this.series.name == 'Recovered'||'Targeted' ? '%' : ''); } } 

So that both of these series add%. But this method does not work for me. Any ideas? Thank you very much.

+4
source share
1 answer

I discovered how to do this - leaving a question in case it helps someone else. The correct syntax for this is:

 tooltip: { formatter: function() { return ''+ this.x +': '+ this.y + (this.series.name == 'Recovered(%)'||this.series.name =='Defaulted(%)' ? '%' : ''); } 
+6
source

All Articles