Hide dataset by default using Chart.js - Javascript Chart.js

Javascript examples for Chart.js:Chart Data

Description

Hide dataset by default using Chart.js

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <title>ChartJS Line Chart</title> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.3.0/Chart.js"></script> 
      <script type="text/javascript">
    window.onload=function(){//from  w  w w .j  a va2s  .c  o  m
var options = {
  type: 'line',
  data: {
    labels: ["Red", "Blue", "Yellow", "Green", "Purple", "Orange"],
    datasets: [
       {
         label: '# of Votes',
         data: [12, 19, 3, 5, 2, 3],
         borderWidth: 1
       },
         {
            label: '# of Points',
            data: [7, 11, 5, 8, 3, 7],
            borderWidth: 1
         }
      ]
  },
  options: {
     scales: {
       yAxes: [{
        ticks: {
               reverse: false
        }
      }]
    }
  }
}
var ctx = document.getElementById('chartJSContainer').getContext('2d');
var chart = new Chart(ctx, options);
chart.getDatasetMeta(1).hidden=true;
chart.update();
    }

      </script> 
   </head> 
   <body>  
      <canvas id="chartJSContainer" width="600" height="400"></canvas>   
   </body>
</html>

Related Tutorials