2013-05-02 71 views
0

我使用正值和負值創建條形圖並顯示每個數據點的xAxis(類別名稱)(請參閱小提琴:http://jsfiddle.net/engemasa/eMjGg/)。數據標籤放置 - 與圖表數據相反(正值和負值)

這裏就是我有情節的選擇,但我不知道我需要什麼其他(真的只是把這個代碼在這裏,因爲我需要包括一些代碼鏈接到的jsfiddle)

plotOptions : { 
      series : { 
       dataLabels: { 
        formatter: function() { 
         return this.x 
        }, 
        enabled: true 
       } 
      } 
     }, 

我試圖放置標籤,使其與圖表上每個條的起始位置對齊。我photoshoped我想要的結果:http://i.imgur.com/0I1jSHW.png

任何幫助將不勝感激。

回答

1

可以遍歷每個datalabel和使用翻譯( )功能移動SVG元素。

http://jsfiddle.net/eMjGg/7/

$.each(chart.series[0].data,function(i,data){ 

     position = chart.yAxis[0].toPixels(0); 

     console.log(data); 
     if(data.y < 0) 
      position-=10; 
     else 
      position-=70; 

     data.dataLabel.attr({ 
      x:position 
     }); 
    }); 
+0

好極了!非常感謝你!!! – Scott 2013-05-07 15:40:18

相關問題