Saturday, September 22, 2012

Line Graph Using Google

Chart.html

I got this piece of code from google api site .
It is pretty handy in generating a line graph


<html>
  <head>
    <script type="text/javascript" src="https://www.google.com/jsapi"></script>
    <script type="text/javascript">
      google.load("visualization", "1", {packages:["corechart"]});
      google.setOnLoadCallback(drawChart);
      function drawChart() {
        var data = google.visualization.arrayToDataTable([
          ['Year', 'Sales', 'Expenses','Profit'],
          ['2004',  1000,      400,1000-400],
          ['2005',  1170,      460,1170-460],
          ['2006',  660,       1120,660-1120],
          ['2007',  1030,      540,1030-540],
            ['2008',  1030,      540,1030-540]
        ]);

        var options = {
          title: 'Company Performance'
        };

        var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
        chart.draw(data, options);
      }
    </script>
  </head>
  <body>
    <div id="chart_div" style="width: 900px; height: 500px;"></div>
  </body>
</html>

No comments:

Post a Comment