Highcharts多个系列的自定义工具提示

时间:2016-08-29 14:06:20

标签: javascript jquery highcharts

我正在构建一个可以包含多达5种不同类型数据系列的高清图。我将类似的系列放在一起,因此不同的系列会有3个不同的y轴。

我遇到的问题是,如果值为On或{{1},我无法更改其中一个系列的工具提示Off100 }。

目前我使用的是共享工具提示,但每个数据系列都有自己的工具提示。 5个中的4个仅在工具提示上使用前缀/后缀,例如0%amps等。

不幸的是,我无法通过将工具提示更改为On或Off来使其工作。这就是我尝试过的。

psig

我不想使用全局工具提示格式化器,因为我已经将工具提示格式构建到每个不同的类型中,这些类型在传递多个数据系列时与switch语句相关联。

使用此代码

dataSeries.push({

    name: currData['name'],
    type: 'line', // Type of visual display
    width: 0.4,
    yAxis: currData['yAxis'],
    data: currData['series'],
    tooltip: {

        pointFormat: '{series.marker} {series.name}: ' + ('{value}' == 100 ? '<b>On</b><br />' : '<b>Off</b><br />')


        //valueSuffix: '{value}' === 100 ? 'On' : 'Off'

        formatter: function () {
            // Cant get any of these to work
            return '{value}' == 100 ? 'On' : 'Off';
            return this.y == 100 ? 'On' : 'Off';
            return this.point.y == 100 ? 'On' : 'Off';

        }
    }
    //zones: currData['seriesZones'],       
}

它不会在工具提示中显示标记。

Missing colored markers when using point formatter

1 个答案:

答案 0 :(得分:6)

扩展Grzegorz的解决方案,包括显示标记:

  tooltip: {
    pointFormatter: function() {
      var point = this;
      return '<span style="color:' + point.color + '">\u25CF</span> ' + point.series.name + ': <b>' + (point.y > 0 ? 'On' : 'off') + '</b><br/>';
    }
  }

http://jsfiddle.net/0u915g9b/1/

请注意,默认html显示在文档中:http://api.highcharts.com/highcharts/series%3Cline%3E.tooltip.pointFormatter

相关问题