You need to take the "new" out of the date strings, ie: {"v": "new
Date(2008, 2, 30, 0, 31, 26)", "f": "3/30/08 12:31 AM"} becomes {"v":
"Date(2008, 2, 30, 0, 31, 26)"} (you can keep the formatted values if you
like, but using a
DateFormatter<https://developers.google.com/chart/interactive/docs/reference#dateformatter>is
cleaner). Keep the column type as "date".
On Thursday, July 26, 2012 5:23:10 AM UTC-4, snowLeopard wrote:
>
> Hi
>
> I am trying to populate the chart with data using JSON string but get the
> following error:
>
> Invalid JSON string:
>
> {
> cols:[{id:'A', label:'Fruit', type:'string'},{id:'B', label:'Year',
> type:'date'},{id:'C', label:'Systolic', type:'number'},{id:'D',
> label:'Diastolic', type:'number'},],
> rows:[{c:[{v:'Patients'}, {v:new Date (1901,0, 1)}, {v:160}, {v:
> 100}]},{c:[{v:'Patients'}, {v:new Date (1902,0, 1)}, {v:180}, {v:
> 120}]},{c:[{v:'Patients'}, {v:new Date (1903,0, 1)}, {v:100}, {v: 80}]},]
> }
>
> My function:
>
> function drawChart(data) {
> var dataTbl = new google.visualization.DataTable(data);
> var motionchart = new
> google.visualization.MotionChart(document.getElementById('chart'));
> motionchart.draw(dataTbl, { 'width': 800, 'height': 400 });
> }
>
> where data is:
> {
> cols:[{id:'A', label:'Fruit', type:'string'},{id:'B', label:'Year',
> type:'date'},{id:'C', label:'Systolic', type:'number'},{id:'D',
> label:'Diastolic', type:'number'},],
> rows:[{c:[{v:'Patients'}, {v:new Date (1901,0, 1)}, {v:160}, {v:
> 100}]},{c:[{v:'Patients'}, {v:new Date (1902,0, 1)}, {v:180}, {v:
> 120}]},{c:[{v:'Patients'}, {v:new Date (1903,0, 1)}, {v:100}, {v: 80}]},]
> }
>
> I tested this on www.jsonlint.org and its not valid. But when I change it
> to valid JSON by using double quotes:
>
> {"cols": [{"id": "A", "label": "NEW A", "type": "string"},
> {"id": "B", "label": "B-label", "type": "number"}, {"id": "C",
> "label": "C-label", "type": "date"} ],"rows": [{"c":[{"v": "a"}, {"v":
> 1.0, "f": "One"}, {"v": "new Date(2008, 1, 28, 0, 31, 26)", "f": "2/28/08
> 12:31 AM"}]}, {"c":[{"v": "b"}, {"v": 2.0, "f": "Two"}, {"v": "new
> Date(2008, 2, 30, 0, 31, 26)", "f": "3/30/08 12:31 AM"}]},
> {"c":[{"v": "c"}, {"v": 3.0, "f": "Three"}, {"v": "new Date(2008, 3, 30, 0,
> 31, 26)", "f": "4/30/08 12:31 AM"}]} ]}
>
> I get the message: "All data columns must be string or numbers". What is
> the correct JSON to use?
>
>
--
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/-/RPtgH3bDekMJ.
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.