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

时间:2013-01-28 14:45:41

标签: javascript highcharts

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

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

如上所述在最后一行中,如果此系列名称为“已恢复”,则添加'%',否则不添加任何内容。

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

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

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

1 个答案:

答案 0 :(得分:6)

我已经发现了如何做到这一点 - 如果有人帮助其他人,请留下疑问。正确的语法是:

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