7 messages in com.googlegroups.google-visualization-api[visualization-api] Re: Question abou...
FromSent OnAttachments
Lin01 Jul 2008 03:26 
Google VizGuy01 Jul 2008 04:29 
Lin Li01 Jul 2008 04:57 
Google VizGuy01 Jul 2008 05:11 
Lin Li01 Jul 2008 05:29 
Google VizGuy01 Jul 2008 05:35 
Lin Li01 Jul 2008 05:55 
Subject:[visualization-api] Re: Question about Data Queries
From:Lin Li (lili@gmail.com)
Date:07/01/2008 05:55:03 AM
List:com.googlegroups.google-visualization-api

Thank you so much. Now I understand what my problem is .

On 01/07/2008, Google VizGuy <viz@google.com> wrote:

use this to access your sheet:

var query = new google.visualization.Query(' http://spreadsheets.google.com/tq?key=pcEYDYVzR46YRrl2XXzPZTg<http://spreadsheets.google.com/pub?key=pcEYDYVzR46YRrl2XXzPZTg> &pub=1&range=a1:c7'<http://spreadsheets.google.com/tq?key=poAg-4S6PGg8xhw1OVp3YLA&pub=1&range=a1:c7%27> );

On Tue, Jul 1, 2008 at 3:29 PM, Lin Li <lili@gmail.com> wrote:

Hello,

Thanks. I tried your published spreadsheet, http://spreadsheets.google.com/pub?key=poAg-4S6PGg8xhw1OVp3YLA . It worked well. However, I tried my own published spreadsheet, http://spreadsheets.google.com/pub?key=pcEYDYVzR46YRrl2XXzPZTg .However, it couldn't work.

In your code: var query = new google.visualization.Query(' http://spreadsheets.google.com/tq?key=poAg-4S6PGg8xhw1OVp3YLA&pub=1&range=a1:c7'<http://spreadsheets.google.com/tq?key=poAg-4S6PGg8xhw1OVp3YLA&pub=1&range=a1:c7%27> );

I just replaced the Query url with my new url: var query = new google.visualization.Query(' http://spreadsheets.google.com/pub?key=pcEYDYVzR46YRrl2XXzPZTg &pub=1&range=a1:c7'<http://spreadsheets.google.com/tq?key=poAg-4S6PGg8xhw1OVp3YLA&pub=1&range=a1:c7%27> );

Did I miss some important steps?

Many thanks Lynn

On 01/07/2008, Google VizGuy <viz@google.com> wrote:

I tried this myself and it worked well. I added a table also for debug. The code is below. My (published) spreadsheet is here: http://spreadsheets.google.com/pub?key=poAg-4S6PGg8xhw1OVp3YLA. Note that since I access published data, there is an additional pub=1 parameter in the query base url. I can omit the range=a1:c7 parameter to read the entire sheet.

<html> <head> <script type="text/javascript" src="http://www.google.com/jsapi "></script> <script type="text/javascript"> google.load("visualization", "1", {packages:["piechart", "table"]}); google.setOnLoadCallback(initialize); function initialize() { var query = new google.visualization.Query(' http://spreadsheets.google.com/tq?key=poAg-4S6PGg8xhw1OVp3YLA&pub=1&range=a1:c7'<http://spreadsheets.google.com/tq?key=poAg-4S6PGg8xhw1OVp3YLA&pub=1&range=a1:c7%27> ); query.setQuery('select C, sum(B) group by C'); query.send(handleQueryResponse); } function handleQueryResponse(response) { if (response.isError()) { alert('Error in query: ' + response.getMessage() + ' ' + response.getDetailedMessage()); return; } var data = response.getDataTable(); var chart = new google.visualization.PieChart(document.getElementById('chart_div')); chart.draw(data, {width: 400, height: 240, is3D: true}); var table = new google.visualization.Table(document.getElementById('table_div')); table.draw(data, {showRowNumber: true}); } </script> </head> <body> <div id="chart_div"></div> <div id="table_div"></div> </body> </html>

On Tue, Jul 1, 2008 at 2:57 PM, Lin Li <lili@gmail.com> wrote:

Sorry, I still have some problems.

In test.html: 1. var query = new google.visualization.Query(' http://spreadsheets.google.com/tq?key=pcEYDYVzR46YRrl2XXzPZTg&range=A2:C6&gid=0'<http://spreadsheets.google.com/tq?key=pcEYDYVzR46YRrl2XXzPZTg&range=A2:C6&gid=0%27>);

2. query.setQuery('select C, sum(B) group by C');

The spreadsheet "test" looks like: A B C Value Salary name 1 10 X 2 20 Y 3 30 X 4 40 X 5 50 Z

Firstly I chose "range=A1:C6". Secondly, I chose "range=A2:C6" However, I failed to display the piechart in both of them.

Regards Lynn

On 01/07/2008, Google VizGuy <viz@google.com> wrote:

It is hard to test without access to your spreadsheet, but here is a guess: The columns of the spreadsheet are the "A,"B","C" and so on that appear on top (automatically), *not* part of your data. Try to make your spreadseet look something like this:

A B C Value Salary name 1 10 X 2 20 Y 3 30 X 4 40 X 5 50 Z

and test your query again. If this does not work, please publish your spreadsheet so that I can look at the data and try the code myself.

On Tue, Jul 1, 2008 at 1:26 PM, Lin <lili@gmail.com> wrote:

Hello,

I tried to use Data Queries and followed the documentation step by step. But I still have a problem.

According to the documentation http://code.google.com/apis/visualization/documentation/queries.html , I created a test.html:

<html> <head> <script type="text/javascript" src="http://www.google.com/jsapi"></ script> <script type="text/javascript"> google.load("visualization", "1", {packages:["piechart"]}); google.setOnLoadCallback(initialize); // Set callback to run when API is loaded function initialize() { var query = new google.visualization.Query('http:// spreadsheets.google.com/tq? key=pcEYDYVzR46YRrl2XXzPZTg&range=A1:C6&gid=0'<http://spreadsheets.google.com/tq?key=pcEYDYVzR46YRrl2XXzPZTg&range=A1:C6&gid=0%27> ); query.setQuery('select C, sum(B) group by C'); query.send(handleQueryResponse); // Send the query with a callback function } function handleQueryResponse(response) { if (response.isError()) { alert('Error in query: ' + response.getMessage() + ' ' + response.getDetailedMessage()); return; } var data = response.getDataTable(); var chart = new google.visualization.PieChart(document.getElementById('chart_div')); chart.draw(data, {width: 400, height: 240, is3D: true}); } </script> </head> <body> <div id="chart_div"></div> </body></html>

The functions "initialize" and "handleQueryResponse" are just the same as the documentation. I just created a spreadsheet like this: B C 10 1 20 2 30 3 40 4 50 5

However, when I double clicked the test.html, it couldn't display a piechart.

Did I do something wrong? How can I solve this problem?

Many Thanks Lynn