Highcharts:基于多个系列名称的条件工具提示(OR逻辑运算符)

Gid*_*eon 4 javascript highcharts

通常可以使用以下类型的代码根据高图中系列的名称调整工具提示格式:

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

上面说的在最后一行,如果这个系列名称是'Recovered',那么添加'%'否则不添加任何东西.

但是我希望我的两个系列中的%不只是一个,所以我想添加一个OR运算符,比如

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

因此,这两个系列都添加了%.但上述方法对我不起作用.有任何想法吗?非常感谢.

Gid*_*eon 6

我已经发现了如何做到这一点 - 留下问题以防万一它可以帮助其他人.正确的语法是:

tooltip: {
                formatter: function() {
                    return ''+
                        this.x +': '+ this.y +
                        (this.series.name == 'Recovered(%)'||this.series.name =='Defaulted(%)' ? '%' : '');
                }
Run Code Online (Sandbox Code Playgroud)