Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Charts: Date Error

I am using the Google Visualization API to generate an annotation chart. I fetch articles and their dates from my database. The dates are in the string format 'YYYYMMDD'.

While creating the data table for the chart, I am using the following code to add the date.

dataTable.addColumn('date', 'ArticleDate');
dataTable.addColumn('string', 'ArticleInfo');
        for(i=0;i<searchResultsJSON.length;i++){
            var yearValue = parseInt(searchResultsJSON[i].date.substr(0,4));
            var monthValue = parseInt(searchResultsJSON[i].date.substr(4,6)) - 1;
            var dayValue = parseInt(searchResultsJSON[i].date.substr(6,8));
            dataTable.addRow([Date(yearValue,monthValue,dayValue),'<a class=\"tooltipLink\" onclick=\"getDoc(\''+searchResultsJSON[i].path+'\');return false;\">'+searchResultsJSON[i].title+'</a><br/\><br/\>']);
        }

Now, I would like to know the number of articles on each day, so I run an aggregation query on the datatable.

var result = google.visualization.data.group(dataTable,[0],[{'column': 0, 'aggregation': google.visualization.data.count, 'type': 'date'}]);

However, I am stuck at this point with an error with the date format.

Error: Type mismatch. Value Mon Jun 16 2014 13:08:20 GMT+0200 (W. Europe Daylight Time) does not match type date in column index 0
at Error (native)

This has taken most of the morning and is really holding up progress. Any help at all would be great.

Thanks!

like image 594
Krishna Chaitanya Avatar asked Oct 21 '22 06:10

Krishna Chaitanya


1 Answers

You are missing the new keyword in front of your Date constructor:

dataTable.addRow([new Date(yearValue,monthValue,dayValue),'<a class=\"tooltipLink\" onclick=\"getDoc(\''+searchResultsJSON[i].path+'\');return false;\">'+searchResultsJSON[i].title+'</a><br/\><br/\>']);
like image 102
asgallant Avatar answered Oct 23 '22 00:10

asgallant