Custom Properties to Handler Function

43 views
Skip to first unread message

Jay

unread,
Apr 24, 2012, 1:24:45 AM4/24/12
to google-visua...@googlegroups.com
Does anyone know the easiest way to set additional or custom parameters to the handler function?

var query = new google.visualization.Query(URL);
var queryString = "Select * limit 20";
query.setQuery(queryString);
query.send(handleResponse);

function handleResponse(response){
  // response[myCustomVariable]  #how to set this variable?
}

asgallant

unread,
Apr 24, 2012, 10:16:29 AM4/24/12
to google-visua...@googlegroups.com
I'm not sure what your purpose here is - why would you need to modify anything in the response object?  Or are you asking how to pass a value for "myCustomVariable" to the handleResponse function?

If the latter case is what you are after, then you can get around the problem by passing the Query#send() method an anonymous function, like this:

var myCustomVariable;
query.send(function (response) {
    // this is the query response handler function
    // use myCustomVariable in here
});

Jay

unread,
Apr 24, 2012, 12:35:46 PM4/24/12
to google-visua...@googlegroups.com
Hi ,

Thanks for your response.

I just wanted to know, is there an explicit way to pass additional parameter to the handler function other than the default response object.

My purpose was to generate N number of charts in the same page, with the N requests made consecutively and each request differ from one another by few properties like Query, URL Parameters etc.

I resolved it by the following method.

<div id='chart1'></div>
<div id='chart2'></div>

var query = {};
var queryString = {};
var temp = null;

for(var i=0;i<2;i++){
  temp = i; 
  query[temp]   = new google.visualization.Query(URL+temp);
  queryString[temp] = "Select Col"+temp+ " limit 20"; 
  query[temp].setQuery(queryString[temp]);
  (function(inIndex){
    query[inIndex].send(function(response){
        response['displayIndex'] = inIndex;
        handleResponse(response);
     });
     );  
  })(temp);
}


function handleResponse(response){
   // pass the relevant container name to the chart instance.
}

Let me know if there is a better way than this. 

Thanks



asgallant

unread,
Apr 24, 2012, 1:09:57 PM4/24/12
to google-visua...@googlegroups.com
Pretty much everything I can think of is a variant on what you're doing already, so as long as that works, I'd go with it.
Reply all
Reply to author
Forward
0 new messages