2012-10-25 54 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个数据对象。 –