[英]Google Charts: Date Error
I am using the Google Visualization API to generate an annotation chart. 我正在使用Google Visualization API生成注释图表。 I fetch articles and their dates from my database.
我从我的数据库中获取文章及其日期。 The dates are in the string format 'YYYYMMDD'.
日期采用字符串格式“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! 谢谢!
您在Date
构造函数前面缺少new
关键字:
dataTable.addRow([new Date(yearValue,monthValue,dayValue),'<a class=\"tooltipLink\" onclick=\"getDoc(\''+searchResultsJSON[i].path+'\');return false;\">'+searchResultsJSON[i].title+'</a><br/\><br/\>']);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.