George George - 1 year ago 200
Javascript Question

converting Google Visualization Query result into javascript array

The url to the spreadsheet I am querying is

The query url being used is

Is there a way to convert or store this result in a JavaScript array?

var dis = ["The Walt Disney Company","Entertainment",.1]

I need to be able to manipulate the data at one point and add the new data to the visualization.

Data from one of multiple queries --> Convert to array --> Manipulate data ex: multiplying an input --> data.addRows(manipulated input);

Answer Source

Your query does return a string containing JSON wrapped in a function call:

var responseText = 'google.visualization.Query.setResponse({…});';

This is because you specified out: as an argument for tqx (see Google Developers guides).

If you want it all raw, you can extract and parse the JSON of multiple queries and push the data to an array, so you end up with an array of arrays of row data. For your single query, you could start from something like this:

responseJSON = JSON.parse(
var rowsArray = [];
    var rowArray = [];
    row.c.forEach(function(prop){ rowArray.push(prop.v); });
console.log(rowsArray); // ===  [["The Walt Disney Company", "Entertainment", 0.1]]
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download