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 accomplish below?
plotOptions: {
series: {
events: {
legendItemClick: function(event) {
if(this.yAxis.series[0].visible && this.yAxis.series[1].visible) {
// do some action
}
}
}
}
},
General event handlers for the series items. These event hooks can also be attached to the series at run time using the Highcharts.addEvent function. Fires after the series has finished its initial animation, or in case animation is disabled, immediately as the series is displayed.
In styled mode, the data labels can be styled with the .highcharts-data-label-box and .highcharts-data-label class names ( see example ). Options for the series data sorting. A description of the series to add to the screen reader information about the series. Defaults to undefined.
These pages outline the chart configuration options, and the methods and properties of Highcharts objects. Feel free to search this API through the search bar or the navigation tree in the sidebar.
In styled mode, the color can be defined by the colorIndex option. Also, the series color can be set with the .highcharts-series , .highcharts-color- {n}, .highcharts- {type}-series or .highcharts-series- {n} class, or individual classes given by the className option. Defaults to undefined.
You 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
}
}
}
}
},
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With