0

Is there a way that I can change the default behaviour of the Legend click handler in Highcharts.js so that when I click on a legend label it isolates the series, instead of hiding it. I.e. it should hide all other series on the chart.

http://jsfiddle.net/adamtsiopani/rNkBs/

legend: {
        layout: 'vertical',
        align: 'right',
        verticalAlign: 'top',
        useHTML: true,
        labelFormatter: function () {
            console.log(this);
            return this.name + ' <a class="isolate-series">[isolate]</a>';
        }
    },
Adam
  • 1,932
  • 2
  • 32
  • 57
  • Take a look at these threads http://stackoverflow.com/questions/10604952/how-to-modify-highcharts-legend-item-click-event http://stackoverflow.com/questions/8880748/hiding-a-highcharts-series-without-using-the-legend – Anton Garcia Dosil May 06 '13 at 14:35

1 Answers1

1

Is this what you want? Fiddle Link

Based on the API you have to add a click handler using legendItemClick to apply to the series.

     plotOptions: {
            series:{
                   events: {
                        legendItemClick: function(event) {
                            if (!this.visible)
                                return true;

                            var seriesIndex = this.index;
                            var series = this.chart.series;

                            for (var i = 0; i < series.length; i++)
                            {
                                if (series[i].index != seriesIndex)
                                {

                                    series[i].visible ? series[i].hide() : series[i].show();
                                } 
                            }

                            return false;
                        }
                   }
             }
        }
Cy Pangilinan
  • 562
  • 1
  • 7
  • 22
  • this pretty much does what I want, but it performs very slowly with 50 series. Any idea how to improve performance? – Adam May 06 '13 at 16:24
  • I have no idea how to improve the performance of this, since the Y-axis is also dynamically built based on the data shown. If there was a way to cache the `series` used in that handler so that it doesn't pull all the series every time a legend is clicked, I think performance would improve. – Cy Pangilinan May 06 '13 at 19:55