Display Different Number of Groups in Highcharts Stacked Column Graph

99封情书 提交于 2019-12-11 18:33:39

问题


I am trying to create a column highchart that is stacked and grouped, but I only want the last few x-values to have multiple groups/stacks. The first x-values only have one group/stack.

To explain, I am charting historical values and then comparing optimistic and conservative forecast scenarios.

Here is my jsFiddle. A better way to do this?

 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
        }]

回答1:


Basically highcharts is awesome and you can stack bars and give them relevant data on a point basis. I passed the following for my series array, with additional attrs to passs to the tooltip. See 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},
]


来源:https://stackoverflow.com/questions/13074095/display-different-number-of-groups-in-highcharts-stacked-column-graph

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!