Annotation Chart - Uncaught Error: Type mismatch. Value Date(2017, 2, 17, 10, 49, 21) does not match type datetime

67 views
Skip to first unread message

Dmitry Tumannik

unread,
Mar 15, 2017, 8:07:01 AM3/15/17
to Google Visualization API
Hello.
I'm in trouble with that. 
function drawChart() {
var chart = new google.visualization.AnnotationChart(document.getElementById('chart_div'));
function updateData () {
$.ajax({
url: 'getData.php',
dataType: 'json',
success: function (json) {
data = new google.visualization.DataTable(json);
data.addColumn('datetime', 'Date');
data.addColumn('number', 'Number');
data.addRows(json);
chart.draw(data);
},
error: function() {
console.log('nodata');
}
});
}

setTimeout(function () {
updateData();
}, 1000);
}

getData:
$string = file_get_contents("testData.json");
echo $string;

JSON:
[
["Date(2017, 2, 17, 10, 49, 21)",386],["Date(2017, 2, 17, 10, 51, 15)",452],["Date(2017, 2, 17, 10, 50, 35)",327]
]

What I am doing wrong?

Daniel LaLiberte

unread,
Mar 15, 2017, 9:19:23 AM3/15/17
to Google Visualization API
Thanks for reporting this.  For some reason, the string notation for dates and datetimes is not working.  Until we fix it, you will have to use JavaScript date constructors.  e.g. new Date(2017, 2, 17, 10, 49, 21) without the quotes.


--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualization-api+unsub...@googlegroups.com.
To post to this group, send email to google-visualization-api@googlegroups.com.
Visit this group at https://groups.google.com/group/google-visualization-api.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-visualization-api/73de14b5-efd2-4f16-9b2d-43921b83956a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--

Daniel LaLiberte

unread,
Mar 15, 2017, 9:54:27 AM3/15/17
to Google Visualization API
Sorry, my mistake.  This use of the string format for dates and datetimes has not ever worked when used with the addRows() method.  If you need to pass date strings, you will need to use the actual strict json representation shown in the example here:  https://developers.google.com/chart/interactive/docs/datesandtimes#dates-and-times-using-the-date-string-representation

This is because the only reason you need to use this string representation of dates and datetimes is for json which doesn't permit the 'new' keyword to construct dates.  For consistency, I expect we should be able to support this same format in other cases as well.




To unsubscribe from this group and stop receiving emails from it, send an email to google-visualization-api+unsubscr...@googlegroups.com.
--

Dmitry Tumannik

unread,
Mar 16, 2017, 7:21:59 AM3/16/17
to Google Visualization API
Ok. I added an actual strict json representation and wasn't seen data points ( http://prnt.sc/ekmlav ). Console has no errors.
Code:
{
"cols": [
{"id":"","label":"","pattern":"","type":"datetime"},
{"id":"","label":"","pattern":"#.######","type":"number"}
],
"rows": [
{"c":[{"v":"Date(2017, 2, 17, 10, 49, 21)","f":1.008876}]},
{"c":[{"v":"Date(2017, 2, 18, 10, 51, 15)","f":2.007845}]},
{"c":[{"v":"Date(2017, 2, 19, 10, 50, 35)","f":3.006823}]}
]
}
I don't know why..

Can I use other format files or data(txt, array)? Do you have examples? I need that data refreshing dynamically. Maybe arrayToDataTable() helps me? 
Maybe you know some hacks? I found this conversation ( https://groups.google.com/forum/#!searchin/google-visualization-api/Row$20given$20with$20size$20different$20than|sort:relevance/google-visualization-api/jM7M4i2nEwE/vRo4p4JJq0wJ )
Your reply will be higly appreciated.


среда, 15 марта 2017 г., 15:54:27 UTC+2 пользователь Daniel LaLiberte написал:
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualization-api+unsub...@googlegroups.com.
To post to this group, send email to google-visua...@googlegroups.com.



--



--

Daniel LaLiberte

unread,
Mar 16, 2017, 9:29:37 AM3/16/17
to Google Visualization API
Your data does not mean what you think it means.  For example:

    {"c":[{"v":"Date(2017, 2, 17, 10, 49, 21)","f":1.008876}]}

This is only specifying one column of data, where the value ("v") is the date, "Date(2017, 2, 17, 10, 49, 21)", and the formatted representation ("f") is 1.008876.  What you need is two columns of data, more like:

    {"c":[{"v":"Date(2017, 2, 17, 10, 49, 21)"},{"v":1.008876}}]}



To unsubscribe from this group and stop receiving emails from it, send an email to google-visualization-api+unsubscr...@googlegroups.com.
--



--

--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualization-api+unsub...@googlegroups.com.
To post to this group, send email to google-visualization-api@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Reply all
Reply to author
Forward
0 new messages