Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Highcharts: Conditional tooltip based on multiple series names (OR logic operator)

It is usual to be able to adjust the tooltip format based on the the name of the series in highchart, using the following type of code:

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

The above says in the last line, if this series name is 'Recovered' then add '%' else don't add anything.

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

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

So that both those series have the % added. But the above method does not work for me. Any ideas? Thanks very much.

like image 246
Gideon Avatar asked Jan 28 '13 14:01

Gideon


1 Answers

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

tooltip: {
  formatter: function() {
    return ''+
           this.x +': '+ this.y +
           (this.series.name == 'Recovered(%)'||this.series.name =='Defaulted(%)' ? '%' : '');
  }
}
like image 192
Gideon Avatar answered Oct 03 '22 01:10

Gideon