datetime column type and charts

791 views
Skip to first unread message

gigitek

unread,
Dec 22, 2010, 7:00:27 AM12/22/10
to Google Visualization API
I want to create a graph (AnnotatedTimeLine ) from this spreadsheet:
https://spreadsheets.google.com/ccc?key=0AhgU7I4IfehhdHFaZGRlZzMxWFNXejhzdUN6dDhpQVE

The problem is that the first column, A, containg the dates is
retrieved as string not as date time, as AnnotatedTimeLine expects
Firebug reports this: First column must contain date, or date and
time.
I formatted the column as date time using the 123 drop down menu.

from the HTML source:
function drawVisualization() {
// To see the data that this visualization uses, browse to
// http://spreadsheets.google.
com/ccc?key=pCQbetd-CptGXxxQIG7VFIQ
var query = new google.visualization.Query(
'http://spreadsheets.google.com/tq?
key=0AhgU7I4IfehhdHFaZGRlZzMxWFNXejhzdUN6dDhpQVE');

// Apply query language.
query.setQuery('SELECT A,B,C');

// Send the query with a callback function.
query.send(handleQueryResponse);
}

function handleQueryResponse(response) {
if (response.isError()) {
alert('Error in query: ' + response.getMessage() + ' ' +
response.getDetailedMessage());
return;
}

var data = response.getDataTable();
var annotatedtimeline = new
google.visualization.AnnotatedTimeLine(document.getElementById('visualization'));
annotatedtimeline.draw(data, {'displayAnnotations':
true});
}

Thank you

ChartMan

unread,
Dec 26, 2010, 2:21:16 AM12/26/10
to google-visua...@googlegroups.com
So this is somewhat tricky but here is what happened.

When you first type something in a cell then there is an auto-detect mechanism that identifies what it is. e.g. "1" is the number 1, "1 Jun" is the date 06/01/2010 etc.
In the sheet example all the date cells were inserted with the date "20.12.2010" which is not one of the supported date formats, as such it was recognized as a string.
Since strings can not be translated to any other data types, then nothing you apply from the format menu ("123" menu) changed the cells to be dates.

To fix the problem I changed all the strings in column A to spreadsheet dates (you can see that all cells are now right aligned which means that they were identified as a non string type).
You can now chart the annotated timeline like requested.

HTH
ChartMan



--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
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.


Reply all
Reply to author
Forward
0 new messages