Sunday 8 December 2013

2 Creating a Google Chart using data pulled from Google Docs

I have data lying in this Google Docs spreadsheet. that I want to display in this blog post or in any other html page using Google Charts.

The first task is to publish this data on the web and make it visible to anyone who has the URL.

Next take the following piece of code and insert it into your website.

<script type="text/javascript" src=""></script>
<script type="text/javascript">
google.load("visualization", '1', {packages:['corechart']});
function drawChart() {
  var query = new google.visualization.Query(


function handleQueryResponse(response) {
  if (response.isError()) {
    alert('Error in query: ' + response.getMessage() + ' ' + response.getDetailedMessage());

  var data = response.getDataTable();
  var options = {'title':'How Much PIZZA I Ate Last Night',
  var chart = new google.visualization.PieChart(document.getElementById('columnchart'));
  chart.draw(data, options);

<title>Data from a Spreadsheet</title>

<span id='columnchart'></span>

Note the URL of the spreadsheet  :    and use this in the function drawChart()

and this what you get :
Data from a Spreadsheet
the same code can be embedded in a no-blog HTML page and loaded into a webserver as seen here.

No comments:

Post a Comment