有沒有辦法在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