简体   繁体   English

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

[英]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:通常能够根据 highchart 中系列的名称调整工具提示格式,使用以下类型的代码:

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但是我希望我的两个系列有 % 而不仅仅是一个,所以我想添加一个 OR 运算符,例如

    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.非常感谢。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM