setQuery parameters passed to Python data source?

25 views
Skip to first unread message

Toby Glidewell

unread,
Oct 4, 2013, 1:11:34 PM10/4/13
to pygoog...@googlegroups.com
My newbie implementation of a bar chart with a Python data source is currently working, but I'd like to pass a query string using the google.visualization.Query.setQuery function. How can I receive that query string in my Python data-source code? My log file indicates it is not being passed in sys.argv. The Google documentation does not indicate how to pass query parameters to Python data sources.

Thanks, TG

Here is the HTML:

<html>
<head>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
  google.load("visualization", "1", {packages:["corechart"]});
  google.setOnLoadCallback(initialize);

  function initialize()
  {
      // Send the query with a callback function.
      var query = new google.visualization.Query("http://localhost/my_data_query.py");
      query.setQuery("select C, sum(B) group by C");
      query.send(handleQueryResponse);
  }

  function handleQueryResponse(response)
  {
      var options =
      {
          title: 'Event Counts',
          vAxis: {title: 'ID',  titleTextStyle: {color: 'red'}},
          hAxis: {title: 'Event Count',  titleTextStyle: {color: 'blue'}}
      };
 
      if (response.isError())
      {
          alert('Error in query: ' + response.getMessage() + ' ' + response.getDetailedMessage());
          return;
      }

      var data_table = response.getDataTable();
      var chart = new google.visualization.BarChart(document.getElementById('chart_div'));
      chart.draw(data_table, options);
  }

</script>
</head>
<body>
  <div id="chart_div" style="height: 5000px;"></div>
</body>
</html>

Here is the Python data source, my_data_query.py:

import sys
import logging
import logging.config

from ServeChartData import emit_chart_data

logging.config.fileConfig("logging.conf")
logger = logging.getLogger("emit_chart_data")
logger.debug("sys.argv: {0}".format(sys.argv)) 
# Emit the Google charts data
try:
    # Queries the database and returns a response via the data_table.ToJSonResponse
    emit_chart_data()
except Exception as ex:
     pass




Toby Glidewell

unread,
Oct 5, 2013, 10:44:24 AM10/5/13
to pygoog...@googlegroups.com
I've worked around the setQuery handling by implementing ordinary CGI GET handling, as shown here
Reply all
Reply to author
Forward
0 new messages