I'm working on a page that brings in various data from a google spreadsheet, and need to loop in order to draw multiple visualizations from multiple queries. In order to do this I'd like to run a loop which
- queries the spreadsheet
- alters returned data to fit my needs
- graphs the altered data.
I've tried multiple techniques, after altering the data I haven't been able to send it back to the parent function. Is there some special technique / syntax I need to use to return the object?
Currently (for step 2) I have:
function handleQueryResponse(response) {
if (response.isError()){
alert('Error in query: ' + response.getMessage() + ' ' + response.getDetailedMessage());
return;
}
//DataTable comes in is formatted wrong. Formatting for pie graphs below.
var data = response.getDataTable();
var dataView = new google.visualization.DataView(data);
var new_data_table = new google.visualization.DataTable(
{
cols: [{id: 'time', label: 'Time taken', type: 'string'},
{id: 'results', label: 'Number of results', type: 'number'}],
rows: [
{c:[{v: 'Two days or less'}, {v: dataView.getValue(0,0) }]},
{c:[{v: 'Two days to one week'}, {v: dataView.getValue(0,1) }]},
{c:[{v: 'One to two weeks'}, {v: dataView.getValue(0,2)}]},
{c:[{v: 'Two weeks or more'}, {v: dataView.getValue(0,3)}]}]},
0.5
);
return new_data_table;
}
Unfortunately, if you try to document.write the output from the function, it always comes back undefined. For example
this_data_table = query.send(handleQueryResponse);
is undefined, even though inside the handleQueryResponse function
document.write(new_data_table.toSource());
works fine. Additionally
this_string = query.send(handleQueryResponse);
where
function handleQueryResponse(response){ [...] return new_data_table.toString() ;}
also comes back undefined. Maybe there's something incredibly obvious that I'm missing, but this has been frustrating me all morning. For some context here is my static prototype page.