简体   繁体   English

Highcharts仅在链接的系列之间共享工具提示

[英]Highcharts sharing tooltip between linked series only

I'm making a chart with an confidence interval bound like this: https://www.highcharts.com/demo/arearange-line 我正在制作一个具有这样的置信区间的图表: https : //www.highcharts.com/demo/arearange-line

It works great, but when there is more than one dataset (so, more than two series), the shared tooltips affect every series, when I only want it to mention the series (not the min and max values, and not the other line) the mouse is hovered over, as if shared were false. 效果很好,但是当有多个数据集(因此,有两个以上系列)时,共享工具提示会影响每个系列,而我只希望它提及系列(而不是最小值和最大值,而不是另一行) )将鼠标悬停在鼠标上,就好像shared是假的一样。

Here's my relevant configuration: 这是我的相关配置:

tooltip: {
    shared: true,
},

series: [{
    data: averages,
    zIndex: 1,
}, {
    data: ranges,
    type: 'arearange',
    linkedTo: ':previous',
    zIndex: 0,
}, {
    data: averages2,
    zIndex: 1,
}, {
    data: ranges2,
    type: 'arearange',
    linkedTo: ':previous',
    zIndex: 0,
}]

And here it is demonstrated in a jsfiddle: https://jsfiddle.net/ktd39x97/ 此处在jsfiddle中进行了演示: https ://jsfiddle.net/ktd39x97/

Does anyone have any ideas how I can get around this? 有谁知道如何解决这个问题?

Highcharts doesn't support that kind of behavior of shared tooltip - there can be only one for all series. Highcharts不支持共享工具提示的这种行为-所有系列只能有一个。

Workaround: 解决方法:

This custom code can mimic the desired behavior using the standard no-shared tooltip: 此自定义代码可以使用标准的非共享工具提示来模仿所需的行为:

  tooltip: {
    formatter: function(e) {
      var point = this.point,
        series = point.series,
        chart = series.chart,
        correspondingSeries = series.linkedSeries[0] || series.linkedParent,
        linePoint,
        arearangePoint;

      // unselect previously selected point
      if (chart.extraHoveredPoint) {
        chart.extraHoveredPoint.setState('');
      }

      // find corresponding point
      if (correspondingSeries) {
        correspondingPoint = correspondingSeries.points[point.index];
        correspondingPoint.setState('hover');
        chart.extraHoveredPoint = correspondingPoint;
      }

      // identify type of points for formatting purposes
      if (point.low !== undefined) {
        arearangePoint = point;
        linePoint = correspondingPoint;
      } else {
        arearangePoint = correspondingPoint;
        linePoint = point;
      }

      return "Line: " + linePoint.y + "<br>" + "Arearange: " + arearangePoint.low + " - " + arearangePoint.high;

    }
  },

API refences: API参考:

Live demo: https://jsfiddle.net/BlackLabel/gq1d1aba/ 现场演示: https : //jsfiddle.net/BlackLabel/gq1d1aba/

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

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