5

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!

  • substr(0,5) wont that give you YYYYM ? – DaImTo Jun 16 '14 at 11:57
  • Sorry, I'd posted a previous version of the code I was working on. The one I'm using now has the right indices for substring, but the problem still persists. – Krishna Chaitanya Jun 16 '14 at 12:32
  • What value is returned by `Date(yearValue, monthValue, dayValue)` ? If you trying to parse('08') - please read http://stackoverflow.com/questions/17681843/lint-warning-parseint-missing-radix-parameter – Krzysztof Safjanowski Jun 16 '14 at 13:01

1 Answers1

3

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/\>']);
asgallant
  • 25,536
  • 6
  • 68
  • 83