hide legend for first and last series - Javascript highcharts

Javascript examples for highcharts:Chart Series

Description

hide legend for first and last series

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=function(){//from   www  .ja  v a 2  s .  c  om
var points = [
   { name: 'department 1', y: 45 },
  { name: 'department 2', y: 68 },
  { name: 'department 3', y: 82 },
  { name: 'department 4', y: 37 }
]
Highcharts.chart('container',     {
        chart: {
            type: 'bar'
        },
        title: {
            text: 'Compare scores per department'
        },
        xAxis: {
            type: 'category'
        },
        plotOptions: {
              series: {
               events: {
                 legendItemClick: function () {
                     if (this.visible) {
                     this.setData([], false)
                  } else {
                     this.setData([points[this.index]], false);
                  }
                }
              }
            },
            bar: {
                grouping: false,
                dataLabels: {
                   enabled: true,
                }
            }
        },
        credits: {
            enabled: false
        },
        series: [
            { name: 'department 1', data: [points[0]] },
            { name: 'department 2', data: [points[1]] },
            { name: 'department 3', data: [points[2]] },
            { name: 'department 4', data: [points[3]] }
        ]
    });
    }

      </script> 
   </head> 
   <body> 
      <script src="https://code.highcharts.com/highcharts.js"></script> 
      <div id="container" style="height: 300px"></div>  
   </body>
</html>

Related Tutorials