Google Column charts auto-sorting - Javascript Google Chart

Javascript examples for Google Chart:Column Chart

Description

Google Column charts auto-sorting

Demo Code

ResultView the demo in separate window

<html lang="en">
   <head> 
      <title>Sorting google charts</title> 
   </head> 
   <body translate="no"> 
      <script type="text/javascript" src="https://www.google.com/jsapi?autoload={'modules':[{'name':'visualization','version':'1.1','packages':['corechart']}]}"></script> 
      <div id="chart_div" style="width: 900px; height: 500px;"></div> 
      <script>
            google.setOnLoadCallback(drawVisualization);
      function drawVisualization() {
          var data = [/*from   ww  w  . j a  va  2  s.  c o m*/
              ["Month", "Shipments"],
              [String(new Date("2015-05-01T04:00:00.000Z")), 51666],
              [String(new Date("2014-11-01T04:00:00.000Z")), 53783],
              [String(new Date("2015-02-01T05:00:00.000Z")), 63454],
              [String(new Date("2014-12-01T05:00:00.000Z")), 63722],
              [String(new Date("2015-03-01T05:00:00.000Z")), 63836],
              [String(new Date("2015-09-01T04:00:00.000Z")), 63884],
              [String(new Date("2015-04-01T04:00:00.000Z")), 68869],
              [String(new Date("2015-08-01T04:00:00.000Z")), 68954],
              [String(new Date("2015-01-01T05:00:00.000Z")), 72110],
              [String(new Date("2015-06-01T04:00:00.000Z")), 77942],
              [String(new Date("2015-07-01T04:00:00.000Z")), 86856],
              [String(new Date("2014-10-01T04:00:00.000Z")), 92168]
          ];
          // Some raw data (not necessarily accurate)
          var data = google.visualization.arrayToDataTable(data);
          data.sort([{column: 1}, {column: 0}]);
          var chart = new google.visualization.ColumnChart(document.getElementById('chart_div'));
          chart.draw(data);
      }
      </script>  
   </body>
</html>

Related Tutorials