You need to use an intermediary function:

query.send(function (response) {
    drawDocsTableCallback(response, element);
});

and give the callback function an element parameter:

function drawDocsTableCallback(response, element) {
    //...
}

On Friday, June 7, 2013 6:45:40 PM UTC-4, Will Gardner wrote:
>
> Hello All,
>
> I'm not massively experienced with JavaScript or Google Visualization API 
> so I could be missing something obvious. It seems impossible to set up a 
> generalised function to create a visualization for an external data source, 
> whilst I can easily generalise the input URL for the external data is is 
> from my current understanding not possible to pass the specific element I 
> would like to attach the visualization to through to the query callback 
> function.
>
> Here's what I've got:
>
> <script type="text/javascript">
>     function drawDocsTable( url, div-id ) {
>       // Can easily set the URL I wish to grab the data from
>       var query = new google.visualization.Query( url );
>       
>       // The callback function cannot take additional parameters..
>       query.send( drawDocsTableCallback );
>     }
>     function drawDocsTableCallback(response) {
>       if (response.isError()) {
>         alert('Error in query: ' + response.getMessage() + ' ' + 
> response.getDetailedMessage());
>         return;
>       }
>     
>       var data = response.getDataTable();
>       
>       // Therefore I can only have a static element
>       visualization = new 
> google.visualization.Table(document.getElementById('table'));
>       visualization.draw(data, null);
>     }
> </script>
>
> I'd rather not have to create a new callback function for every different 
> visualization. I considered putting the element into a global scope 
> variable, but if I call this function again before the data is fetched then 
> it would get overridden.
>
> Thoughts?
>
> Will
>

-- 
You received this message because you are subscribed to the Google Groups 
"Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at 
http://groups.google.com/group/google-visualization-api?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to