2012-06-08 70 views
9

我正在使用Highcharts,我想绘制垂直线的值。喜欢;如何在Highcharts图上绘制垂直线?

enter image description here

我怎么能这样做?谢谢。

这里是我的代码

 <script type="text/javascript"> 

$(function() { 
    var chart; 
$(document).ready(function() { 

    chart = new Highcharts.Chart({ 
     chart: { 
      renderTo: 'container', 
      type: 'area' 
     }, 
    title: { 
     text: '<b> </b>' 
    }, 
     xAxis: { 

      labels: { 
       formatter: function() { 
        return this.value; // clean, unformatted number for year 
       } 
      } 
     }, 
     yAxis: { 
      labels: { 
       formatter: function() { 
        return this.value/1000 +'k'; 
       } 
      } 
     }, 
     tooltip: { 
      formatter: function() { 
       return '<b>'+ Highcharts.numberFormat(this.y, 0) +'</b>'; 
      } 
     }, 
      xAxis: { 
     categories: [ 
      'Mon', 
      'Tue', 
      'Wed', 
      'Thu', 
      'Fri', 
      'Sat', 
      'Sun' 
     ], 
     plotBands: [{ // visualize the weekend 
      from: 5.5, 
      to: 6.5, 
      color: 'rgba(68, 170, 213, .2)' 
     }] 
    }, 

     plotOptions: { 

      area: { 
       pointStart: 1, 
       marker: { 
        enabled: false, 
        symbol: 'circle', 
        radius: 1, 
        states: { 
         hover: { 
          enabled: true 
         } 
        } 
       } 
      } 
     }, 
     series: [{ 
      name: 'Visit', 
      data: [946, 733, 764, 887, 832,1423] 
     }, { 
      name: 'Unique', 
      data: [746, 633, 664, 687,702,1266] 
     }] 
    }); 
}); 

}); 
    </script> 
+1

顺便说一句,你不需要了'$(函数(){...'和'$(document).ready(function(){...'在一起,它们都是一样的东西 – Jamiec

回答

10

对于此任务,您最有可能不得不使用Highcharts renderer,因为您要执行的操作与网格不太匹配,并且不太适合绘图线。

我做了一个very simple example,根据您的代码显示绘制任意垂直线,在一个硬编码的位置。为了实现你的目标,你将不得不计算一些东西,比如每行起始点的x/y位置,以及基于该点值的行的高度。

下面是带有zIndex的slightly different example和您实际需要的一条线,使用V path命令绘制垂直线。

2

如果你想ONY一条线(和面积从开始):

xAxis:{  
    plotLines: [{ 
     color: 'red', // Color value 
     //dashStyle: 'solid', // Style of the plot line. Default to solid 
     value: + new Date(), // Value of where the line will appear 
     width: '2' // Width of the line  
    }], 
    plotBands: [{ 
     color: '#FFFAFA', // Color value 
     from: +new Date(), // Start of the plot band 
     to: +new Date()+1000*24*3600*30, //30 days 
    }], 
}