Hiding a Highcharts series without using the legend

bokov picture bokov · Jan 16, 2012 · Viewed 40.7k times · Source

I need to be able to hide a Highcharts series from a button rather than the legend (the reason is that I need to toggle multiple groups from one button: Hiding _groups_ of series in Highcharts and jQuery: how to get acceptable performance? and for the reasons given in that post, I cannot use $(chart.series).each() with jQuery.

None of the following expressions have any effect (my chart object is named chart):

Chart.series.get(1).hide();
chart.series.get(1).hide();
$(chart.series[1]).hide();
$(chart.series["1"]).hide();
$(chart.series[1]).hide();
$(chart.series)["1"].hide();
$(chart.series)[1].hide();

Can someone please tell me how I can make a chart series hide if I know its index? Thanks.

Answer

eolsson picture eolsson · Jan 16, 2012

This should work:

chart.series[index].hide()

Full example on jsfiddle

(UDP URL from Simen Echholt comment)