Date type in DataTable object

17 views
Skip to first unread message

sandreev

unread,
Dec 20, 2011, 2:52:46 AM12/20/11
to Google Visualization API
I am working on something that is very similar to
http://code.google.com/apis/chart/interactive/docs/php_example.html.
And, there is an issue with the date field that I pull from the
database.
I am not able to populate the date the way I want to, so that I can
sort and draw a graph that is time based.

In the example below if I were to have a date column, how should it be
printed?
{
"cols": [
{"id":"","label":"Topping","pattern":"","type":"string"},
{"id":"","label":"Slices","pattern":"","type":"number"}
],
"rows": [
{"c":[{"v":"Mushrooms","f":null},{"v":3,"f":null}]},
{"c":[{"v":"Onions","f":null},{"v":1,"f":null}]},
{"c":[{"v":"Olives","f":null},{"v":1,"f":null}]},
{"c":[{"v":"Zucchini","f":null},{"v":1,"f":null}]},
{"c":[{"v":"Pepperoni","f":null},{"v":2,"f":null}]}
]
}

I tried the following with no success.
{"c":[{"v":new Date(2010, 11, 28, 0, 31, 26),"f":null}
{"c":[{"v":"new Date(2010, 11, 28, 0, 31, 26)","f":null}
{"c":[{"v":new Date(2010, 11, 28),"f":null}

If anyone has a solution for this please your help in this matter is
very much appreciated.

Thank you,

asgallant

unread,
Dec 20, 2011, 8:59:36 AM12/20/11
to google-visua...@googlegroups.com
Date's are not valid in the JSON spec, so what you want is a string in the form "Date(...)".  Do not use the "new" keyword.
Reply all
Reply to author
Forward
0 new messages