Draw ON/OFF chart - Javascript Google Chart

Javascript examples for Google Chart:Chart Configuration

Description

Draw ON/OFF chart

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(){/*w  w  w .  j  a  va2 s. co m*/
google.charts.load("current", {
    packages: ["timeline"]
});
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
    var container = document.getElementById('visualization');
    var chart = new google.visualization.Timeline(container);
    var dataTable = new google.visualization.DataTable();
    dataTable.addColumn({
        type: 'string',
        id: 'Role'
    });
    dataTable.addColumn({
        type: 'date',
        id: 'Start'
    });
    dataTable.addColumn({
        type: 'date',
        id: 'End'
    });
    dataTable.addRows([
        ['Active', new Date(1789, 3, 30, 1, 0, 0), new Date(1789, 3, 30, 2, 0, 0)],
        ['Active', new Date(1789, 3, 30, 4, 0, 0), new Date(1789, 3, 30, 7, 0, 0)],
        ['Active', new Date(1789, 3, 30, 10, 0, 0), new Date(1789, 3, 30, 20, 0, 0)],
    ]);
    var options = {
        hAxis: {
            format: "HH:mm",
            backgroundColor: '#fafafa'
        }
    };
    chart.draw(dataTable, options);
}
    }

      </script> 
   </head> 
   <body> 
      <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script> 
      <div id="visualization"></div>  
   </body>
</html>

Related Tutorials