2012-10-25 65 views
0

我想創建一個堆疊並分組的柱狀圖,但我只想要最後幾個x值有多個組/堆棧。第一個x值只有一個組/堆棧。在Highcharts堆積列圖中顯示不同數量的組

爲了解釋,我繪製了歷史數據,然後比較了樂觀和保守的預測情景。

這是我的jsFiddle。更好的方法來做到這一點?

series: [{ 
      name: 'Thermal', 
      data: [5, 3, 4, 5], 
      stack: 'conservative', 
      color:'blue' 
     }, { 
      name: 'PV', 
      data: [3, 4, 4, 6], 
      stack: 'conservative', 
      color: 'red' 
     }, { 
      name: 'Thermal', 
      data: [0, 0, 0, 10], 
      stack: 'optimistic', 
      color: 'blue', 
      showInLegend: false 
     }, { 
      name: 'PV', 
      data: [0,0,0, 12], 
      stack: 'optimistic', 
      color: 'red', 
      showInLegend: false 
     }] 
+0

當然。你可以指定每個點的數據點是什麼棧和組。 – wergeld

+0

我明白了,但是如果我這樣做並且爲第二個堆棧的第一個x值填充0,那麼該列仍然是偏離中心的。我想知道是否有正式的方法來做到這一點 - 無論是通過拆分圖表還是通過圖表選項。 –

+0

我想你需要給我們更多關於你的數據本身的信息。你能提供一個示例數據集來說明問題和/或建立一個jsFiddle嗎? – wergeld

回答

0

基本上highcharts是真棒,你可以堆積酒吧,並給他們相關的數據的基礎上。我爲我的系列數組傳遞了以下內容,其他attrs傳遞給工具提示。請參見jsFiddle here

series:[ 
     {name:'Apples', color:'green', data:[{x:0, y:10, year: '2009', scenario: 'historic'}, {x:1, y:11,year: '2010', scenario: 'historic'} ]}, 
     {name:'Oranges', color:'orange', data:[{x:0, y:2, year: '2009', scenario:'historic'}, {x:1, y:5, year: '2010', scenario:'historic'}]}, 
     {name:'Apples',color:'green', data:[{x:1.75, y:12, year:'2011',scenario:'optimistic'}], showInLegend: false }, 
     {name:'Apples', color:'green',data:[{x:2.25, y:3,year:'2011', scenario:'conservative'}], showInLegend: false }, 
     {name:'Oranges',color:'orange', data:[{x:1.75, y:11, year:'2011',scenario:'optimistic'}], showInLegend: false}, 
     {name:'Oranges',color:'orange', data:[{x:2.25, y:6, year:'2011',scenario:'conservative'}], showInLegend: false}, 
] 
+0

您還應該結合第3個和第4個以及第5個和第6個數據對象。 –