Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Highcharts - change column stacking on click

I have a lovely Highcharts plot with stacked columns. I'd like a button which can toggle whether the stacking is 'normal' or 'percent'.

I'm trying the following (which doesn't work):

  $('#button').click(function () {
        var chart = $('#container').highcharts();
        chart.options.plotOptions.column.stacking = 'percent';
        chart.redraw();
  });

Fiddle here: http://jsfiddle.net/CRKcj/2/

Any help would be much appreciated!

like image 520
ewels Avatar asked Aug 28 '13 10:08

ewels


1 Answers

It's not possible to change plotOptions in real time. Instead you can update options for each series instead, for example:

$('#button').click(function () {
    var chart = $('#container').highcharts(),
        s = chart.series,
        sLen = s.length;

    for(var i =0; i < sLen; i++){
        s[i].update({
            stacking: 'percent'   
        }, false);   
    }
    chart.redraw();
});

Jsfiddle demo here.

like image 180
Paweł Fus Avatar answered Oct 22 '22 12:10

Paweł Fus