36

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.

Community
  • 1
  • 1
bokov
  • 3,444
  • 2
  • 31
  • 49

1 Answers1

64

This should work:

chart.series[index].hide()

Full example on jsfiddle

(UDP URL from Simen Echholt comment)

Alexander Selishchev
  • 1,180
  • 13
  • 29
eolsson
  • 12,567
  • 3
  • 41
  • 43
  • 5
    [Here is a working jsFiddle](http://jsfiddle.net/gh/get/jquery/1.7.2/highslide-software/highcharts.com/tree/master/samples/highcharts/members/series-hide/) linked to from the [highcharts docs for `series.hide`](http://api.highcharts.com/highcharts#Series.hide) – Simen Echholt Apr 10 '14 at 21:37
  • Do you know if it is possible to remove the series entirely from the legend? Not just make it grey. – michaelAdam Aug 05 '14 at 14:22
  • michaelAdam: you have to do `chart.series[index].remove(true)` (http://api.highcharts.com/highcharts#Series.remove) – Hernan S. Oct 29 '14 at 20:15
  • 1
    It would be nice to have functionality like remove() that completely hides a series, but then just put it back just as easily. [I have a stupid complicated UI that has every single feature my manager could imagine, with zero consideration towards keeping it simple.] – Gerry Sep 27 '19 at 15:33