dimanche 31 janvier 2016

Fetching data from spreadsheet in script: "Data table is not defined"

I’m trying to make a script using the Google Visualization App Geomap. In the example code on the Google Developers page, they are using a hard coded table. What I want to do, is to make code use data from a Google Spreadsheet connected to a Google Form. More specifically, I want to use the data of the spreadsheet tab «countries» from the following spreadsheet: http://ift.tt/1NJRScb.

Somehow this does not work, and I get the error messages listed below.

How can I collect the data from the spreadsheet in the right format? I have attempted to use this procedure to collect the data from the spreadsheet: http://ift.tt/1M0dNkD.

Error message on web page:

"Data table is not defined"

Error message in Safari Console:

TypeError: undefined is not an object (evaluating 'new google.visualization.Query’)
drawChart help:113
(anonymous function) help:117

My code

<script type="text/javascript" src="http://ift.tt/JuZcy0"></script>
<script type="text/javascript">
  google.load("visualization", "1", {packages:["geomap"]});
  google.setOnLoadCallback(drawMap);

  function drawMap() {
    var opts = {sendMethod: 'auto'};

    // ***My code***
    var query = new google.visualization.Query('http://ift.tt/1NJRTwy', 'sheet=countries', 'headers=1');
    var data = query.send(handleQueryResponse);

    var options = {};
    options['dataMode'] = 'regions';

    var container = document.getElementById('regions_div');
    var geomap = new google.visualization.GeoMap(container);

    geomap.draw(data, options);
  };

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

      return response.getDataTable();
    }

</script>

Hope there is someone out there who can help me with this (hopefully) not so hard task. Thank you very much in advance! :-)




Aucun commentaire:

Enregistrer un commentaire