Highcharts同步图表显示工具提示 [英] Highcharts Synchronized charts display tooltip

查看:181
本文介绍了Highcharts同步图表显示工具提示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在同步图表中显示工具提示.请参阅此 Jsfiddle

I want to display tooltip in Synchronized charts. Please see this 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
      }
    }
  });

工具提示只能显示第一个系列,而不能显示第二个系列,即使鼠标悬停在第二个系列上.

The tooltip can only display the first series but no second series, even mouse hover the second series.

请咨询.

推荐答案

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

First you have to set the tooltip-Option shared to true. Then you have to update the mousemove touchmove touchstart-Eventhandler to deal with multiple series/points

$('#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
              }
          }
      }
});

请参阅 http://jsfiddle.net/doc_snyder/51zdn0jz/6/更新小提琴.我已亲切地接受了此帖子 http:中链接的代码: //forum.highcharts.com/highcharts-usage/synchronize-chart-with-shared-tooltip-t33919/.

See http://jsfiddle.net/doc_snyder/51zdn0jz/6/ for your updated fiddle. I have graciously taken the code linked in this Post http://forum.highcharts.com/highcharts-usage/synchronize-chart-with-shared-tooltip-t33919/.

这篇关于Highcharts同步图表显示工具提示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆