0

Trying to make visible false of legend series items on legendItemClick event in highcharts, But not working. How to do it?

Below is my code.

  series: {
  events: {
    legendItemClick: function(e) {
      const series = this;
      const chart = series.chart;
      const hasChangedOpacity = series.hasChangedOpacity;
      
      if(this.name == 'Movie1' || this.name == 'Movie2'){  
         chart.series[2].visible = false;
         chart.series[3].visible = false; 
      }
      
      if(this.name == 'Game1' || this.name == 'Game2'){
         chart.series[0].visible = false;
         chart.series[1].visible = false;
      } 
      
    } 
     }
      },   
       series: [{
    name: 'Movie1',
    data: [49.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4],
    visible:true
  }, {
    name: 'Movie2',
    data: [83.6, 78.8, 98.5, 93.4, 106.0, 84.5, 105.0, 104.3, 91.2, 83.5,106.6, 92.3],
    visible:true
  }, {
    name: 'Game1',
    data: [48.9, 38.8, 39.3, 41.4, 47.0, 48.3, 59.0, 59.6, 52.4, 65.2, 59.3,51.2],
    visible:true
  }, {
    name: 'Game2',
    data: [42.4, 33.2, 34.5, 39.7, 52.6, 75.5, 57.4, 60.4, 47.6, 39.1, 46.8,51.1],
    visible:true
  }]

https://www.highcharts.com/demo/column-basic

Demo: https://jsfiddle.net/zny6c9d3/2/

EMahan K
  • 417
  • 1
  • 19
  • For the options to take effect, I'd use `chart.series[2].setData({visible: false});`, etc – kikon Jan 13 '23 at 06:09

0 Answers0