2013-12-13 38 views
0

我在页面中有两个折线图。我正在使用高图来绘制图表。用鼠标移动一条垂直线并找到两个高图的交点

我想用鼠标移动移动一条垂直线,并想找出每条图形的垂直线与图形相交处的数据点。

<!DOCTYPE html> 
    <html> 
<head> 

    <script src="http://code.jquery.com/jquery-1.10.1.min.js"></script> 
    <script src="http://code.highcharts.com/highcharts.js"></script> 
    <style> 
    #reporting { 
    position: absolute; 
    top: 55px; 
    right: 20px; 
    font: 12px Arial, Verdana; 
    color: #666; 
    } 
    </style> 
    <script> 
     $(function() { 
      var $reporting = $('#reporting'); 
      var $reporting1 = $('#reporting1'); 

      $('#container').highcharts({ 
       chart: { 
       }, 
       xAxis: { 
       }, 
       plotOptions: { 
        series: { 
         point: { 
          events: { 
           mouseOver: function() { 
            $reporting.html('x: ' + this.x + ', y: ' + this.y); 
           } 
          } 
         }, 
         events: { 
          mouseOut: function() { 
           $reporting.empty(); 
          } 
         } 
        } 
       }, 
       tooltip: { 
        enabled: false 
       }, 
       series: [{ 
         data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4] 
        }] 
      }); 

      //second chart 
      $('#container1').highcharts({ 
       chart: { 
       }, 
       xAxis: { 
       }, 
       plotOptions: { 
        series: { 
         point: { 
          events: { 
           mouseOver: function() { 
            $reporting1.html('x: ' + this.x + ', y: ' + this.y); 
           } 
          } 
         }, 
         events: { 
          mouseOut: function() { 
           $reporting1.empty(); 
          } 
         } 
        } 
       }, 
       tooltip: { 
        enabled: false 
       }, 
       series: [{ 
         data: [9.9, 71.5, 16.4, 129.2, 144.0, 120.0, 135.6, 148.5, 216.4, 194.1, 5.6, 4.4] 
        }] 
      }); 
     }); 
    </script> 
</head> 
<body> 
    <div id="container" style="height: 300px; min-width: 300px"></div> 
    <div id="reporting"></div> 
    <div id="container1" style="height:300px;min-width:300px"></div> 
</body> 
</html> 

它所做的是在html中反映x和y坐标。

但是,当鼠标移动到一个图形上时,应绘制一条垂直线,并且它应该反映一条垂直线与两个图形的交点。

+0

你的小提琴不能正常工作,请修理。 –

+0

它正在工作。但它没有按照我的要求工作,我没有找到任何可以制作垂直线的东西。 – asdfdefsad

+0

它根本不起作用。高图不加载。 GET http://code.highcharts.com/highcharts.js 403(禁止) **使用cdn ** –

回答

2

您可以使用十字线选项,共享工具提示选项以及在单个图表上绘制两条线,并使用2个不同的堆叠x轴来近似此。

看到这个example

在我的例子,我有2个图表之间坐在固定的位置提示,我添加了一个点击事件,打开一个jQuery用户界面与更详细的工具提示对话。但是,你可以有一个正常的提示,而不是...

十字线选项:

1

不支持这样的事情,但是您可以通过为图表添加鼠标移动事件来实现此目的,您将在其中获得event.pageXevent.pageY。现在使用axis.toValue()来获取价值,并将其显示在图表上。要绘制该行,可以使用plotLine并更新该行。