【发布时间】:2011-04-07 23:28:27
【问题描述】:
有没有办法在 Google Visualization API 中从 JSON 中检索日期值? 这是playground 的代码片段请将下面的代码复制到其中
当您运行代码时,您不会得到任何结果。您应该从我用注释标记的日期值中删除引号以检索结果。
function drawVisualization() {
var JSONObject = {
cols:
[
{id: 'header1', label: 'Header1', type: 'string'},
{id: 'header2', label: 'Header2', type: 'date'}
],
rows:
[
{
c:
[
{v: 'Value1'},
{v: "new Date(2010, 3, 28)"} // <= This is the format I receive from WebService
]
},
{
c:
[
{v: 'Value2'},
{v: new Date(2010, 3, 28)} // <=This is the format Google API accepts
]
}
]
};
var data = new google.visualization.DataTable(JSONObject, 0.5);
visualization = new google.visualization.Table(document.getElementById('table'));
visualization.draw(data, {'allowHtml': true});
}
【问题讨论】:
-
哥们,我也有同样的问题!
-
我知道这是一个很老的问题,但我有同样的问题,你可能会有所帮助。这是我的 json
[["Date(2015,6,1)",9,218.0],["Date(2015,7,1)",10,497.5],["Date(2015,8,1)",13,317.5],["Date(2015,9,1)",29,1572.0],["Date(2015,10,1)",34,480.0],["Date(2015,11,1)",20,387.0],["Date(2016,0,1)",34,836.0],["Date(2016,1,1)",29,957.5],["Date(2016,2,1)",2,1250.0],["Date(2016,3,1)",2,793.5],["Date(2016,10,1)",3,801.0],["Date(2016,11,1)",2,756.5],["Date(2017,1,1)",2,410.0]],我得到未捕获的错误:类型不匹配。 Value Date(2015,6,1) 与列索引 0 中的类型日期不匹配。
标签: json date datatable google-visualization