简体   繁体   English

高图:在工具提示中设置系列名称的格式

[英]Highcharts: Format series names in tooltip

I have multiple series on the same chart, and I'd like to use the tooltip formatter to make the series names look readable in the tooltip. 我在同一张图表上有多个系列,并且我想使用工具提示格式化程序使系列名称在工具提示中看起来可读。 At the moment, they're displayed in the form Seriesonename and Seriestwoname , but I'd like them to be displayed in the form Series One Name and Series Two Name . 目前,它们以SeriesonenameSeriestwoname的形式显示,但我希望它们以Series One NameSeries Two Name的形式显示。 I'd still like to keep the tooltip in the same format of Series One Name: 0.567 . 我仍然希望工具提示保持与Series One Name: 0.567相同的格式。

I've done something similar to this when formatting the chart labels, where I used the following code: 在格式化图表标签时,我已经执行了类似的操作,其中使用了以下代码:

legend: {
  labelFormatter: function () {
    return {
      'Seriesonename': 'Series One Name',
      'Seriestwoname': 'Series Two Name'
    }[this.name];
  }
}

I've tried doing the same for the tooltip formatter, but I can't seem to get it to work. 我曾尝试对工具提示格式化程序执行相同的操作,但似乎无法正常工作。 I suspect it's something to do with the fact that it's a shared tooltip, but I'm not 100% sure. 我怀疑这与共享的工具提示有关,但我不确定100%。

Any help would be greatly appreciated! 任何帮助将不胜感激!

To do a similar approach to your legend.labelFormatter for the tooltip you could use tooltip.formatter or tooltip.pointFormatter , somewhat depending on how your chart is set up. 做了类似的做法,以你的legend.labelFormatter你可以使用工具提示tooltip.formattertooltip.pointFormatter ,多少随您的图表是如何设置的。

An example using the tooltip.pointFormatter could be ( JSFiddle ): 使用tooltip.pointFormatter的示例可能是( JSFiddle ):

tooltip: {
    pointFormatter: function() {
        var seriesNameConverter = {
            'Seriesonename': 'Series One Name',
            'Seriestwoname': 'Series Two Name'
        };

        return '<span style="color:{point.color}">\u25CF</span> '
            + seriesNameConverter[this.series.name] + ': <b>' + this.y + '</b><br/>';
    }
}

This is the default style of tooltip.pointFormat with your conversion in place of the series name. 这是tooltip.pointFormat的默认样式,其中您的转换代替了系列名称。

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

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