admin管理员组

文章数量:1400998

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.

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.

Share Improve this question asked Jan 28, 2013 at 14:45 GideonGideon 1,8864 gold badges41 silver badges71 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 7

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(%)' ? '%' : '');
  }
}

本文标签: javascriptHighcharts Conditional tooltip based on multiple series names (OR logic operator)Stack Overflow