有没有办法在Google Visualization API中从JSON中检索日期值? 这里是snipplet为playground请在下面的代码复制进去如何将日期值从JSON返回到Google Visualization API
当你运行你不会有任何结果的代码。您应该从标记为注释的日期值中删除引号以便检索结果。
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});
}
家伙我有同样的问题! – 2010-12-21 09:46:58
我知道这是一个很老的问题,但我有同样的问题,你可能会帮助。这是我的json [[“Date(2015,6,1)”,9,218.0],[“Date(2015,7,1)”,10,497.5],[“Date(2015,8,1)”,13,317.5] [ “日期(2015,9,1)”,29,1572.0],[ “日期(2015,10,1)”,34,480.0],[ “日期(2015,11,1)”,20,387.0],[”日期(2016,0,1) “34,836.0],[ ”日期(2016,1,1)“,29,957.5],[ ”日期(2016,2,1)“,2,1250.0],[” 日期(2016 ,3,1) “2,793.5],[ ”日期(2016,10,1)“,3,801.0],[ ”日期(2016,11,1)“,2,756.5],[” 日期(2017,1,1) “,2,410.0]]'我得到未捕获的错误:类型不匹配。值日期(2015,6,1)与列索引0中的类型日期不匹配。 – 2017-05-22 18:45:00