Highcharts:在工具提示中格式化系列名称

hel*_*ump 1 javascript highcharts

我在同一个图表上有多个系列,我想使用工具提示格式化程序使系列名称在工具提示中看起来可读.目前,他们正在展示的形式SeriesonenameSeriestwoname,但我想他们要显示在形式Series One NameSeries Two Name.我仍然希望将工具提示保持为相同的格式Series One Name: 0.567.

在格式化图表标签时,我做了类似的事情,我使用了以下代码:

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

我已尝试对工具提示格式化程序执行相同操作,但我似乎无法使其工作.我怀疑这与它是一个共享的工具提示这一事实有关,但我不是百分百肯定.

任何帮助将不胜感激!

Hal*_*and 6

legend.labelFormatter对您可以使用的工具提示执行类似的方法,tooltip.formatter或者在tooltip.pointFormatter某种程度上取决于图表的设置方式.

使用的示例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/>';
    }
}
Run Code Online (Sandbox Code Playgroud)

这是tooltip.pointFormat转换的默认样式,而不是系列名称.