这是一个新手问题,但如何在Google Charts line chart中使用x轴的日期?
当我使用新的日期(...)时,我收到错误消息“未捕获错误:不支持日期和日期时间列类型”
google.load("visualization", "1", {packages:["corechart"]});
google.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
['Datum','Person1','Person2','Person3'],
[new Date(2012, 12, 19, 0, 0, 0),'5072.0537223002','5072.0537223002','5074.2809630567'],
[new Date(2012, 12, 20, 0, 0, 0),'5072.0537223002','5072.0537223002','5074.2809630567'],
]);
var options = {};
var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
chart.draw(data, options);
}
(在x轴上使用字符串均匀的空格是可以接受的,但是当我尝试使用字符串时“轴#0的数据列不能是字符串类型”)
2 回答
如何将日期转换为字符串,只需使用
Date
,而不使用new
,如下所示:Edit: 您可以在此链接中关注他们的示例:
https://google-developers.appspot.com/chart/interactive/docs/customizing_axes
Edit 2:
这就是我能做的:http://jsfiddle.net/ANC9H/2/
我希望这有帮助 .
那's because you'重新使用arrayToDataTable() . 如果您使用DataTable(),则错误消息将消失 . 看这篇文章:Column Chart with date axis not working