Note that there are some explanatory texts on larger screens.

plurals
  1. POIssues with Google Visualization API on App Engine
    primarykey
    data
    text
    <p>I have been working on a front end to my App Engine app kind of based on <a href="https://developers.google.com/bigquery/articles/dashboard" rel="nofollow">this codelab.</a> I have a text box where you enter in a stock ticker symbol (like say, AMZN or GOOG), which it uses as criteria to run a query to Google BigQuery in the background and then it's supposed display the tweet count over several days in a Google Visualization API <a href="https://developers.google.com/chart/interactive/docs/gallery/linechart" rel="nofollow">line chart</a>.</p> <p>But, based on what I've seen in the source code from the page, it's not pulling the query results from BigQuery into the data template variable {{ data }}. Here's my HTML code (called index1.html), which for the most part is like the codelab's:</p> <pre><code>&lt;!-- You are free to copy and use this sample in accordance with the terms of the Apache license (http://www.apache.org/licenses/LICENSE-2.0.html) --&gt; &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;head&gt; &lt;meta http-equiv="content-type" content="text/html; charset=utf-8"/&gt; &lt;title&gt; Jibdan Analytics &lt;/title&gt; &lt;script type="text/javascript" src="//www.google.com/jsapi"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; google.load('visualization', '1', {packages: ['corechart']}); &lt;/script&gt; &lt;script type="text/javascript"&gt; countdata = {{ data }} function drawVisualization() { // Create and populate the data table. var data = google.visualization.DataTable(query_response); // Create and draw the visualization. var chart = new google.visualization.LineChart(document.getElementById('visualization')); chart.draw(data, {title: "Tweets by Day by Ticker", curveType: "function", width: 800, height: 600} ); } google.setOnLoadCallback(drawVisualization); &lt;/script&gt; &lt;/head&gt; &lt;body style="font-family: Arial;border: 0 none;"&gt; &lt;div id="visualization" style="width: 800px; height: 640px;"&gt;&lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>I messed with the html and Javascript after looking at the Google Code Playground code for the line chart, but really it seems like the issue is with that template variable.</p> <p>Here's the pertinent Python code, too. The first method is supposed to take the BigQuery response and put it in a format that should be ingested by the Visualization API to produce a line chart. The get method has the query string to run and renders the results into the template, index1.html. Pretty much like the codelab:</p> <pre><code>class QueryHandler(webapp2.RequestHandler): def _bq2line(self, bqdata): logging.info(bqdata) columnNameDate = bqdata['schema']['fields'][0]['name'] columnNameVal = bqdata['schema']['fields'][1]['name'] logging.info("Column Names=%s, %s" % (columnNameDate, columnNameVal)) countdata = { 'cols': ({'id':columnNameDate, 'label':columnNameDate, 'type':'string'}, {'id':columnNameVal, 'label':columnNameVal, 'type':'number'})} countdata['rows'] = []; logging.info(countdata) for row in bqdata['rows']: newrow = ({'c':[]}) newrow['c'].append({'v': row['f'][0]['v']}) newrow['c'].append({'v':row['f'][1]['v']}) countdata['rows'].append(newrow) logging.info('FINAL COUNTDATA---') logging.info(countdata) self.response.out.write(countdata) return json.dumps(countdata) def get(self): QUERY = """ SELECT STRFTIME_UTC_USEC(querydate, "%Y-%m-%d") AS tweet_date, COUNT(tweet_id) AS tweet_count FROM [jibdantweetstream.tweetdata_09_21_2013] WHERE gcs_load = true AND (REGEXP_MATCH(ticker, '""" + self.request.get('stock') + """')) GROUP BY tweet_date ORDER BY tweet_date """ try: query_request = bigquery_service.jobs() query = {'data': self._bq2line(bq.Query(QUERY, BILLING_ID)), 'query': QUERY} query_response = query_request.query(projectId=BILLING_ID, body=query).execute() template = os.path.join(os.path.dirname(__file__), 'result1.html') self.response.out.write(render(template, query_response)) finally: self.response.out.write('&lt;a href="/"&gt;Click here&lt;/a&gt; to go back to the Search page. ') </code></pre> <p>So, that's what I have. You'll see I have a couple of <code>self.response.out.write</code> statements in there, because I wanted to see if I was getting a response back with query results. I am getting results, so I know it's not an OAuth2 issue. I just don't know what else it could be.</p> <p>Many Thanks in Advance.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload