title: How to show and hide legends in google chart
body: <p>Could anyone let me know which is the best method to show/hide line legends (If using a checkbox for changing the visibility).</p>
  
  <p>I should be having maximum 7 legends in line chart.</p>
  
  <p><strong>My code is below:</strong></p>
  
  <pre><code>function DrawGraph(chartsdata, title, charttype) {
  
      //debugger;
      google.charts.load('current', { 'packages': ['corechart'] });
      google.charts.setOnLoadCallback(DrawChart);
  
      function DrawChart() {
          var data = new google.visualization.DataTable();
  
          data.addColumn('string', '');
          data.addColumn('number', '');
  
          try {
  
              var data = google.visualization.arrayToDataTable(chartsdata);
          }
          catch (e) {
              //debugger;
              //document.writeln(e);
          }
  
          var optionsBar = {
              title: title,
              isStacked: true,
              hAxis: {
                  type: "datetime",
                  showTextEvery: 1,
                  ticks: [2016,2017,2018,2019,2020,2021,2022,2023]
              },
              legend: {
                  position: 'bottom',
                  textStyle: { fontSize: 12 }
              }
          };
  
          var optionsLine = {
              title: title,
              //width: 500,
              seriesType: 'line',
              legend: {
                  position: 'bottom',
                  textStyle: { fontSize: 11 }
              }
          };
  
          if (charttype == "line") {
              var chart = new google.visualization.LineChart(document.getElementById('chartdiv'));
              chart.draw(data, optionsLine);
          }
          else {
              var chart = new google.visualization.ColumnChart(document.getElementById('chartdiv'));
              chart.draw(data, optionsBar);
          }
      }
  }
  </code></pre>