I think I found a solution... or at least a work around.

I rewrote my query so that it specifically names the responseHandler
parameter in the url:

    46      var params = "?dt=" + date_string + "&shift_type_id=" +
shift_type_id + "&responseHandler=handle_hppd_chart_setup_response";
    47      var query = new google.visualization.Query("/landing_page/
get_hppd_chart_data" + params);
    48      query.send(handle_hppd_chart_setup_response);

Then in my controller I return something like:
"handle_hppd_chart_setup_repsonse({'status':'OK', ..., 'table':
{cols: .... .... );"

That works.

Basically, instead of relying on the
google.visualization.Query.setResponse method, I had to outright
specify which method to use.

One thing to note though: when I used
google.visualization.Query.setResponse, I got a QueryResponse object
passed to my handler.  Now I just get the inner dictionary parameters
(i.e. {'status':'OK', 'version':'0.6', 'table': {....}}).  This meant
re-tooling the handler so that it didn't try to get the data table
using the response.getDataTable method and instead did a "var
data_table = new google.visualization.DataTable(response.table, 0.6);"
to get the data table object.

So I'm not sure if that was exactly the right way to get a response
handler to trigger multiple times without doing a page reload, but it
worked for me.  It does seem counter intuitive though because the
documentation implies that just doing a query.send(responseHandler)
should do exactly what I wanted in the first place.

Hope this helps someone,

On Jul 7, 1:35 pm, Evan Stern <[email protected]> wrote:
> Ok, I've seen some posts here about this but I haven't been able to
> find any that answer my question specifically.  I have a feeling that
> I'm missing something pretty basic.
>
> I have a line chart that I'm populating via a data source.  The data
> source itself is actually an exposed controller (python using
> turbogears).
>
> I can get the initial chart load to work just fine, but I want to have
> the chart re-load with new data when the user clicks a back or forward
> button on the page.
>
> Here's what I'm doing in my javascript file for the page:
>
>     10  var setup_scheduler_landing_page = function() {
>     ...
>     ...
>     24      setup_hppd_chart('undefined','undefined');
>     25  };
>
>     38  var setup_hppd_chart = function(date_string, shift_type_id) {
>     39      add_spinner($("#hppd_chart"));
>     40
>     41      if ( shift_type_id == 'undefined' ) {
>     42          select_element = $
> ("#hppd_chart_form").children('select')
>     43          shift_type_id = select_element.attr('options')
> [select_element.attr('selectedIndex')].id
>     44      }
>     45
>     46      var params = "?dt=" + date_string + "&shift_type_id=" +
> shift_type_id;
>     47
>     48      var query = new google.visualization.Query("/landing_page/
> get_hppd_chart_data" + params);
>     49      query.send(handle_hppd_chart_setup_response);
>     50
>     51      bind_hppd_chart_nav_click();
>     52  };
>
>     64  var handle_hppd_chart_setup_response = function(response) {
>     65      if ( response.isError() ) {
>     66          alert( "Error in query: " + response.getMessage() + "
> " + response.getDetailedMessage() );
>     67          return false;
>     68      }
>     69
>     70      var data = response.getDataTable();
>     71      var visualization = new
> google.visualization.LineChart(document.getElementById('hppd_chart'));
>     72      visualization.draw(data,{height:220, title:'HPPD Info',
> vAxis:{title:'Hours'}, hAxis:{title:'Dates',textColor:'#666666'}});
>     73  };
>
> I also have a click handler on the back/forward buttons that calls the
> setup_hppd_chart function with updated parameters (for example, if you
> push 'forward', setup_hppd_chart will get passed a date in the future,
> which will return chart data for that date).
>
> If you notice, setup_hppd_chart is where the query is being set up and
> sent out.  Initially I call setup_hppd_chart through a chain of
> commands in the document.ready function.
>
> When I click the back/forward buttons and watch my net requests I see
> that the data source is being hit with the correct parameters and it
> is returning the json response.  For reference, the response looks
> like this:
>
> google.visualization.Query.setResponse({'version':'0.6', 'reqId':'0',
> 'status':'OK', 'table': {cols:[{id:'date',label:'Date',type:'string'},
> {id:'assigned_hours',label:'Hours Assigned',type:'number'},
> {id:'required_hours',label:'Hours Required',type:'number'}],rows:[{c:
> [{v:'Jul, 01'},{v:112.0},{v:122.08}]},{c:[{v:'Jul, 02'},{v:104.0},{v:
> 117.6}]},{c:[{v:'Jul, 03'},{v:104.0},{v:117.6}]},{c:[{v:'Jul, 04'},{v:
> 96.0},{v:117.6}]},{c:[{v:'Jul, 05'},{v:112.0},{v:117.6}]},{c:[{v:'Jul,
> 06'},{v:104.0},{v:117.6}]},{c:[{v:'Jul, 07'},{v:104.0},{v:
> 117.6}]}]}});
>
> Unfortunately, the handle_hppd_chart_setup_response function is not
> called when the above json response is returned.
>
> Again, this all works the first time the page loads, but subsequent
> attempts to get the handle_hppd_chart_setup_response function to
> trigger by calling query.send(handle_hppd_chart_setup_response) just
> don't work.
>
> Does anyone have any idea as to why this doesn't work the way I think
> it should?
>
> I appreciate any help you can offer.
>
> Thanks!

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

Reply via email to