Query Language Reference (Version 0.7) - Scalar Functions

46 views
Skip to first unread message

Michael

unread,
Oct 28, 2011, 10:47:15 AM10/28/11
to Google Visualization API
Hi:

I would like to display just the year on my x axis of the line chart,
however, in my database table the date is stored as a full date. I
came across Scalar functions and it seems that year() function will
return what I am after. I keep getting an "cannot parse query" error.
Can someone point out my syntactical error? The column name is my
database that holds the date values is title "date".




function drawVisualization(name,year) {
//console.log("Inside drawVisualization
function: " + name);
google.visualization.drawChart({
"containerId": "chart_div",
"dataSourceUrl": 'http://www.google.com/
fusiontables/gvizdata?tq=',

"query": "SELECT
year(date),average_ground_water_level FROM 1974520 WHERE name = '" +
name + "'",
"chartType": "LineChart",
"options": {
"title": name,
"vAxis": { "title": "Average Daily
Groundwater Level - (M)" },
"hAxis": {
"title": "Year",

"showTextEvery":"0",
},
"width":"700px"
}
});
}

Thanks in advance,
Michael

asgallant

unread,
Oct 28, 2011, 11:32:41 AM10/28/11
to google-visua...@googlegroups.com
Is the date column being returned as a javascript Date or as a string?  I don't think the time scalar functions work on strings, but I could be wrong.

Michael

unread,
Oct 28, 2011, 12:09:18 PM10/28/11
to Google Visualization API
Hi Asgallant:

I believe its being returned as an object:

google.visualization.Query.setResponse({version:'0.5',reqId:'0',status:'ok',table:
{p:{totalrows:-1},cols:[{id:'col2>>1',label:'date',type:'datetime'},
{id:'col3>>1',label:'average_gr',type:'number'}],rows:[{c:[{v:null},
{v:null}]},{c:[{v:null},{v:null}]},{c:[{v:new Date('Sep 11, 1965
12:00:00 PM')},{v:381.636}]},{c:[{v:new Date('Sep 15, 1965 12:00:00
PM')},{v:381.636}]},{c:[{v:new Date('Sep 24, 1965 12:00:00 PM')},{v:
381.648}]},{c:[{v:new Date('Oct 10, 1965 12:00:00 PM')},{v:381.669}]},
{c:[{v:new Date('Oct 17, 1965 12:00:00 PM')},{v:381.679}]},{c:[{v:new
Date('Oct 24, 1965 12:00:00 PM')},{v:381.679}]},{c:[{v:new Date('Oct
30, 1965 12:00:00 PM')},{v:381.69}]},{c:[{v:new Date('Nov 7, 1965
12:00:00 PM')},{v:381.69}]},{c:[{v:new Date('Nov 14, 1965 12:00:00
PM')},{v:381.688}]},{c:[{v:new Date('Nov 20, 1965 12:00:00 PM')},{v:
381.69}]},{c:[{v:new Date('Nov 27, 1965 12:00:00 PM')},{v:381.679}]},
{c:[{v:new Date('Dec 4, 1965 12:00:00 PM')},{v:381.688}]},{c:[{v:new
Date('Dec 12, 1965 12:00:00 PM')},{v:381.679}]},{c:[{v:new Date('Dec
18, 1965 12:00:00 PM')},{v:381.669}]},{c:[{v:new Date('Dec 26, 1965
12:00:00 PM')},{v:381.667}]},{c:[{v:new Date('Jan 2, 1966 12:00:00
PM')},{v:381.658}]},{c:[{v:new Date('Jan 9, 1966 12:00:00 PM')},{v:
381.658}]},{c:[{v:new Date('Jan 16, 1966 12:00:00 PM')},{v:381.636}]},
{c:[{v:new Date('Jan 22, 1966 12:00:00 PM')},{v:381.636}]},{c:[{v:new
Date('Jan 29, 1966 12:00:00 PM')},{v:381.627}]},{c:[{v:new Date('Feb
5, 1966 12:00:00 PM')},{v:381.627}]},{c:[{v:new Date('Feb 13, 1966
12:00:00 PM')},{v:381.617}]},

asgallant

unread,
Oct 28, 2011, 2:51:55 PM10/28/11
to google-visua...@googlegroups.com
Hmmm...I don't know why that isn't working.

Yinnon Haviv

unread,
Nov 1, 2011, 3:54:43 AM11/1/11
to google-visua...@googlegroups.com
Hi
If the data source your are using does not support the "year()" scalar function, you can always create a data view with a calculated column on top of the query result.

HTH

On Fri, Oct 28, 2011 at 8:51 PM, asgallant <drew_g...@abtassoc.com> wrote:
Hmmm...I don't know why that isn't working.

--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-visualization-api/-/4fbVscXdjrcJ.

To post to this group, send email to google-visua...@googlegroups.com.
To unsubscribe from this group, send email to google-visualizati...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-visualization-api?hl=en.



--
Yinnon Haviv.

Reply all
Reply to author
Forward
0 new messages