Handling multiple queries with Google Visualization API

Google Visualization API supports multiple data queries. So on the client side if you use google.visualization.Query, it automatically increases reqId with every new request you make on the same page. The reason is to identify query responses correctly using reqIds.

In order to make this work, you also have to prepare your query responses with the correct reqId. You can use the following snippet if you are using gviz python library. However the idea is simple extract reqId from request and include it in your response accordingly.

# extract reqId
req_id = 0
tqx = request.GET.get('tqx', None)
if tqx:
    req_id = dict([p.split(':') for p in request.GET.get('tqx', '').split(';')]).get('reqId', 0)
# include it in your response
return HttpResponse(data_table.ToJSonResponse(
                        columns_order=('country', 'visits'),
                        order_by=('visits', 'desc'), req_id=req_id).__str__(),
                        mimetype='text/plain; charset=utf-8')

Leave a Reply

Your email address will not be published.