如何在工具提示高图中获取多个系列数据(不丢失工具提示指针箭头)

时间:2017-03-12 00:22:38

标签: javascript html css highcharts

我的代码现在看起来像这样(下面的演示)

演示:http://jsfiddle.net/pintu31/AcNUM/2/

tooltip: {
        formatter: function() {
            var s = [];

            $.each(this.points, function(i, point) {
                s.push('<span style="color:#D31B22;font-weight:bold;">'+ point.series.name +' : '+
                    point.y +'<span>');
            });

            return s.join(' and ');
        },
        shared: true
    },

当共享为假时,我仍然有指针箭头!如下所示: http://jsfiddle.net/AcNUM/259/

但是当我在第一个演示中使用共享版本时,我丢失了工具提示上的指针箭头:enter image description here

1 个答案:

答案 0 :(得分:0)

使用格式化程序并定义应在工具提示中显示的内容。在格式化程序中,您可以找到与悬停点具有相同类别的点。

tooltip: {
  formatter: function (tooltip) {
    const series = this.series.chart.series.find(series => series !== this.series);
    const point = series.points.find(point => point.category === this.x);

    if (point !== undefined) {
      return tooltip.defaultFormatter.call([point.getLabelConfig(), this], tooltip);
    }
  }
},

示例:http://jsfiddle.net/AcNUM/260/