Thanks, that makes a lot of sense!
However, the documentation doesn't give any examples of how to simply
change a column type. It only explains calc and aggregate. I don't
need to do either. Then, in the DataTable object, I've found the
syntax below, which looks like what I would need.
Unfortunately this doesn't work either. It gives me "Invalid column
input, expected either a number or an object with "calc" and "type"
properties."
Do you have an example how to simply change the column data type
without much overhead?
Thanks!!
mike
function chart2() {
var query = new google.visualization.Query('<my data
source>');
query.setQuery('select month(A), count(C) group by month(A)
pivot B');
query.send(chart2Response);
}
function chart2Response (response) {
if (response.isError()) {
alert('Error in query: ' + response.getMessage() + ' ' +
response.getDetailedMessage());
return;
}
var data = response.getDataTable();
var view = new google.visualization.DataView(data);
//manipulate first column to be a string, so it works as x-
axis label with e.g. stacked columns
view.setColumns([ {column: 0, type: 'string'}, 1, 2, 3 ]);
var chart = new
google.visualization.ColumnChart(document.getElementById('chart2'));
chart.draw(view);
}
On Jul 15, 5:06 pm, Jinji <[email protected]> wrote:
> Try a to wrap the result DataTable with a DataView that transforms the first
> column into a string of your choice. See
> here:http://code.google.com/apis/chart/interactive/docs/reference.html#Dat...
>
>
>
>
>
>
>
> On Fri, Jul 15, 2011 at 1:25 PM, mikew <[email protected]> wrote:
> > I can't seem to figure how to query a flat table into a matrix for
> > e.g. a column chart. Here's the example:
>
> > Let's take a google spreadsheet with deliveries showing the date, type
> > of product and amount delivered:
>
> > DATE | PRODUCT | AMOUNT
> > Jan-1 | Bananas | 10
> > Jan-1 | Apples | 5
> > Jan-1 | Oranges | 7
> > Jan-2 | Bananas | 5
> > Jan-3 | Banana | 7
> > Jan-3 | Oranges | 3
>
> > What is the query that gives me the following table:
>
> > Bananas Apples Oranges
> > January 15 5 10
> > February ... ... ...
> > ...
>
> > I think the query should be: select month(A), sum(C) group by A pivot
> > B
>
> > However, this results in a chart displaying month(a) as one of the
> > data columns (since month is a number I assume) and NOT as labels for
> > the x-axis.
>
> > How can I get it to:
>
> > a) display month as Jan, Feb, Mar, ... instead of 0, 1, 2, ...
>
> > and finally
>
> > b) to display them as labels on the x-axis
>
> > Thanks for any help!
> > mike
>
> > --
> > 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.
--
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.