Google charts to generate chart with date axis - Javascript Google Chart

Javascript examples for Google Chart:Axis

Description

Google charts to generate chart with date axis

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script> 
      <script type="text/javascript">
    window.onload=function(){/*from ww w  .  j  a  v a 2s  .c o  m*/
google.charts.load('current', {packages: ['corechart', 'line']});
  google.charts.setOnLoadCallback(drawLogScales);
  function drawLogScales() {
        var data = new google.visualization.DataTable();
        data.addColumn('string', 'X');
        data.addColumn('number', 'PTH/s');
        data.addRows([
          [new Date('2016-12-15 21:23:07').toString(), 0.78],
          [new Date('2016-12-14 21:23:07').toString(), 5.31],
          [new Date('2016-12-13 21:23:07').toString(), 8.38],
          [new Date('2016-12-12 21:23:07').toString(), 0.72],
          [new Date('2016-12-11 21:23:07').toString(), 3.27],
          [new Date('2016-12-10 21:23:07').toString(), 0.78],
        ]);
        var options = {
          hAxis: {
            title: 'Time (h)',
            logScale: true
          },
          vAxis: {
            title: 'PTH/s',
            logScale: false
          },
          colors: ['#a52714', '#097138']
        };
        var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
        chart.draw(data, options);
      };
    }

      </script> 
   </head> 
   <body> 
      <div id="chart_div"> 
      </div>  
   </body>
</html>

Related Tutorials