fudoki
Posts: 4
Joined: Tue Nov 08, 2011 12:07 pm

Get series index by name

I've got 4 series, 2 of which have legend items. I need to hide (and show) an additional series on legendItemClick.
So when i click on legend item #0, I want to hide #0 and #2. When i click on legend item #1, i want to hide #1 and #3.

I can do this using legendItemClick as shown below - in addition to the the default behaviour hiding/showing item 0, I hide or show item 2. This works fine but i'm building the charts dynamically and I don't know how many series i'll have, let alone which series is which. I do however know the names of all the possible series.

Is there any way to use the name property to identify which series to show and hide?

thanks
//fudoki

Code: Select all

legendItemClick: function(){
             var s = this,
                            series = s.chart.series;
                            if((s.name == "SeriesOne"))
                            {
                                if (s.chart.series[2].visible) { s.chart.series[2].hide(); }
                                    else { s.chart.series[2].show(); }
                            }
                        }
hfrntt
Posts: 6393
Joined: Mon Aug 30, 2010 8:41 am
Contact: Website

Re: Get series index by name

With name you can just loop through all series and check if a given series has some name. However I advice you to use series id. With id you can simply hide series this way:

Code: Select all

chart.get('seriesId').hide()
See get function in options: http://www.highcharts.com/ref/#chart-object
Slawek Kolodziej
Highcharts support team
fudoki
Posts: 4
Joined: Tue Nov 08, 2011 12:07 pm

Re: Get series index by name

Slawek,

Your reply - (series) id is just what I needed - a unique way of addressing a given series without having to worry about it's position in the array.
thanks so much

//fudoki

Return to “Highcharts Usage”