3
votes

I'm using Highcharts for plotting some graphics for my system's users. It works fine, but I'm having some trouble with the stacking option.

To stack a chart, here's what I'm doing:

chart.options.plotOptions.series.stacking = 'normal';

That's how it's done, according to Highcharts API. It works fine; but aside stacking, I also need to show some information to the user, but these information should only be visible if the chart is stacked. So here's what I'm doing:

var stacking = chart.options.plotOptions.series.stacking;
if (stacking == 'normal'){
      //show something
}

That should make sure the chart is stacked, but "stacking" is always returning "undefined" instead of 'normal' or blank - even though in another function I just attributed it 'normal'. Keep in mind "chart" is a global variable, so any changes on it should be accessable by any other JS function.

For details: http://jsfiddle.net/GtjdU/

Any ideas?

2
Do you have JSfiddle, or site? We dont have this code at hand eh? - EricG
Here's a JSfiddle: jsfiddle.net/GtjdU - mtlewis

2 Answers

2
votes

The problem is that you said you did the following:

chart.options.plotOptions.series.stacking = 'normal';
                            ^

But you did it ?
No, if you take a look your fiddle, you'll see that you did the following:

chart.options.plotOptions.column.stacking = 'normal';
                            ^

That's why you're getting undefined

demo

0
votes

You need to define what series you want to know the stacking for.

var stackedVal;
stackedVal = chart.series[0].options.stacking;
alert(stackedVal);

The reason you can't get the global stacking value is because it is on override from the individual series elements. So you could set the plotOptions.series.stacking = 'normal' but in each of the series you can set its own individual stacking. It is always better to read from what a particular series is actually doing.

DEMO