Highcharts同步图表显示工具提示

Tes*_*ter 3 javascript highcharts

我想在同步图表中显示工具提示.请看这个Jsfiddle

 $('#container').bind('mousemove touchmove touchstart', function(e) {
    var chart,
      point,
      i,
      event;

    for (i = 0; i < Highcharts.charts.length; i = i + 1) {
      chart = Highcharts.charts[i];
      event = chart.pointer.normalize(e.originalEvent); // Find coordinates within the chart
      point = chart.series[0].searchPoint(event, true); // Get the hovered point

      if (point) {
        point.onMouseOver(); // Show the hover marker
        chart.tooltip.refresh(point); // Show the tooltip
        chart.xAxis[0].drawCrosshair(event, point); // Show the crosshair
      }
    }
  });
Run Code Online (Sandbox Code Playgroud)

工具提示只能显示第一个系列而不能显示第二个系列,甚至鼠标悬停在第二个系列中.

在此输入图像描述

请指教.

Mar*_*der 7

首先,您必须将tooltip-Option设置shared为true.然后你必须更新mousemove touchmove touchstart-Eventhandler来处理多个系列/点

$('#container').bind('mousemove touchmove touchstart', function(e) {
      var chart,
      points,
      i,
      secSeriesIndex = 1;

      for (i = 0; i < Highcharts.charts.length; i++) {
          chart = Highcharts.charts[i];
          e = chart.pointer.normalize(e); // Find coordinates within the chart
          points = [chart.series[0].searchPoint(e, true), chart.series[1].searchPoint(e, true)]; // Get the hovered point

          if (points[0] && points[1]) {
              if (!points[0].series.visible) {
                  points.shift();
                  secSeriesIndex = 0;
              }
              if (!points[secSeriesIndex].series.visible) {
                  points.splice(secSeriesIndex,1);
              }
              if (points.length) {
                  chart.tooltip.refresh(points); // Show the tooltip
                  chart.xAxis[0].drawCrosshair(e, points[0]); // Show the crosshair
              }
          }
      }
});
Run Code Online (Sandbox Code Playgroud)

请参阅http://jsfiddle.net/doc_snyder/51zdn0jz/6/以获取更新的小提琴.我慷慨地采取了本文中的链接http://forum.highcharts.com/highcharts-usage/synchronize-chart-with-shared-tooltip-t33919/.