score:1

Accepted answer

i think what you are after is a way to make only the clicked legend series show. if that is the case you can do it with the plotoptions.series.events.legenditemclick. to have only one series show up initially on the chart (but still show in the legend) you need to set that series' visible property to true and the others to false. if you want to have all series show on initial load that step can be ignored.

to get the toggle working you need to get the index of the legend item you clicked. you then loop through all the series in your chart to find the one that matches that clicked index. when it matches you set series\[i\].show() for the ones that don't you set series.hide().

here is the basic toggling code:

series: {
    events: {
        legenditemclick: function (event) {
            var seriesindex = this.index;
            var serie = this.chart.series;
            console.log(seriesindex);
            for (i = 0; i < serie.length; i++) {                  
                if (serie[i].index == seriesindex) {
                    serie[i].show();
                    console.log(serie[i].index);
                } else {
                    serie[i].hide();
                }
            }
            return false;
        }
    }
}

and here is a live fiddle.

score:1

when creating chart, just set series.visible = false for series which should be hidden by default.

see docs.


Related Query

More Query from same tag