I have a chart with multiple series which I would like to modify the options of, if two of the series have been disabled by clicking on the legend.
The following won't work as visible
has the value of the state before it was clicked. Is there another way to do what I am trying to acplish below?
plotOptions: {
series: {
events: {
legendItemClick: function(event) {
if(this.yAxis.series[0].visible && this.yAxis.series[1].visible) {
// do some action
}
}
}
}
},
I have a chart with multiple series which I would like to modify the options of, if two of the series have been disabled by clicking on the legend.
The following won't work as visible
has the value of the state before it was clicked. Is there another way to do what I am trying to acplish below?
plotOptions: {
series: {
events: {
legendItemClick: function(event) {
if(this.yAxis.series[0].visible && this.yAxis.series[1].visible) {
// do some action
}
}
}
}
},
Share
Improve this question
asked Dec 31, 2013 at 7:07
dan-klassondan-klasson
14.2k14 gold badges67 silver badges105 bronze badges
1 Answer
Reset to default 7You can get this behavior a little modyfing your function:
plotOptions: {
series: {
events: {
legendItemClick: function(event) {
var series = this.yAxis.series,
seriesLen = series.length,
visible = this.visible ? 1 : -1;
// +1 when visible series, because it will be changed after that callback
for(var i = 0; i < seriesLen; i++) {
if(!series[i].visible) {
visible++;
}
}
if(visible >= 2){
//do some action
}
}
}
}
},