Google Docs query > response.getDataTable > JSOn Objects / Elements

353 views
Skip to first unread message

Kelly B

unread,
Sep 26, 2011, 11:58:12 PM9/26/11
to Google Visualization API
I have run the response.getDataTable function, and logged the returned
elements/obejcts within the response array.
The returned object is referenced with a "U" and the objects within,
(Table labels, and table cell data/rows) are reference by a "B" and
"G" respectively... yesterday they were "A" and "F".
Have tried reading through tonnes of material about the API and JSON ,
but I really don't even know what I'm looking for... what are those
parts of the response data, and why would their references change?

CODE HERE:
var dataSourceUrl = 'http://spreadsheets.google.com/a/xxxxxxxxxxx.com/
tq?tqx=out:json&key=XXXXXxxxxxXXXXXxxxxx';
*XXX used as data is not yet public domain.
var query;
var table_keys = Array(); // contains array of Objects
var table_rows = Array(); // contains array of Objects
var table_whole = Array();
/* Called once Google is good and ready */
function init() {
query = new google.visualization.Query(dataSourceUrl);
query.send(handleQueryResponse);
}

/* Called when the query response is returned. */
function handleQueryResponse(response) {
if (response.isError()) {
alert('Error in query: ' + response.getMessage() + ' ' +
response.getDetailedMessage());
return;
}else{
var data = response.getDataTable();
process_data(data); // Pass requested data to this function for
processing
console.log(data);
}
}

/* Organise the data into easy-to-use arrays */
function process_data(data) {

/* Loop through the key of the table (the first row) */
for (var key in data['B']){
if (data['B'].hasOwnProperty(key)) {
table_keys.push(data['B'][key]); //TODO: Fix this looks really
dodgy?
}
}
/* Loop through the data (all subsequent rows) */
for(var keys in data['G'])
{
if (data['G'].hasOwnProperty(keys)) {
table_rows.push(data['G'][keys]['c']); //TODO: Fix this looks
really dodgy?
}
}

ChartMan

unread,
Sep 27, 2011, 1:28:00 AM9/27/11
to google-visua...@googlegroups.com

Please read this API reference
http://code.google.com/apis/chart/interactive/docs/reference.html#DataTable

ChartMan

> --
> You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
> To post to this group, send email to google-visua...@googlegroups.com.
> To unsubscribe from this group, send email to google-visualizati...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/google-visualization-api?hl=en.
>

asgallant

unread,
Sep 27, 2011, 9:32:10 AM9/27/11
to google-visua...@googlegroups.com
What is your goal with this?  DataTables are already fairly easily parseable using the DataTable#getValue() method.  Other properties of table cells are accessible through other methods listed in the DataTable reference (posted above by ChartMan).
Reply all
Reply to author
Forward
0 new messages