admin管理员组

文章数量:1335357

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: /

Any help would be much appreciated!

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/CRKcj/2/

Any help would be much appreciated!

Share Improve this question edited Aug 28, 2013 at 11:19 Arturs 1,2585 gold badges21 silver badges28 bronze badges asked Aug 28, 2013 at 10:54 ewelsewels 5132 gold badges7 silver badges22 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 8

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.

本文标签: javascriptHighchartschange column stacking on clickStack Overflow