How do you set the stack order of the series in a stacked bar chart?

Viewed 4543

I have been able to control the stacking order of highchart by setting the index field in the series objects like this:

            series: [
                {
                    name: 'My Products',
                    data: randomRange(12, 7, 61), // Just random test data for now.
                    stack: 'ProductType',
                    index: 1 // Here index sets the stacking order in the bar.  This will be on the bottom.
                }, {
                    name: 'Total',
                    data: randomRange(12, 233, 240), // Just random test data for now.
                    stack: 'ProductType',
                    index: 0 // This will be on the top.
                }
            ]

As you can see, a lower index number will be stacked higher in the bar.

enter image description here

Now I am trying to refresh the series, but the stacking order gets lost and I cannot set the index:

            var chart1 = $('#quantityPerMonthChart1').highcharts();
            chart1.series[1].setData(randomRange(12, 233, 240), false);
            chart1.series[1].index = 0;  // Doesn't work.
            chart1.series[0].setData(randomRange(12, 7, 61), false);
            chart1.series[0].index = 1;  // Doesn't work.
            chart1.redraw();
2 Answers
Related