我試圖用谷歌圖表繪製一個時間序列,任何幫助將不勝感激!谷歌圖表不顯示在瀏覽器/ JSON
我正在嘗試顯示折線圖。
我有一個HTML文件,正確下載到客戶端瀏覽器,但沒有顯示。該文件被命名爲gasdata.html
有一個PHP文件調用,輸出(通過回聲)一些json文件,以供上述.html文件使用。
在我的JSON中有沒有缺陷(它確實是正確的)?
我在HTML文件中不正確地實現了Google Charts html嗎?
這裏沒有很多移動部件,但我很茫然。任何幫助深表感謝。
gasdata.html:
<html>
<head>
<!--Load the AJAX API-->
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript">
// Load the Visualization API and the piechart package.
google.load('visualization', '1', {'packages':['corechart']});
// Set a callback to run when the Google Visualization API is loaded.
google.setOnLoadCallback(drawChart);
function drawChart() {
var jsonData = $.ajax({
url: "getData.php",
dataType:"json",
async: false
}).responseText;
// Create our data table out of JSON data loaded from server.
var data = new google.visualization.DataTable(jsonData);
// Instantiate and draw our chart, passing in some options.
var chart = new google.visualization.PieChart(document.getElementById('chart_div'));
chart.draw(data, {width: 400, height: 240});
}
</script>
</head>
<body>
<!--Div that will hold the pie chart-->
<div id="chart_div"></div>
</body>
</html>
輸出JSON:
{
cols: [{label: 'Date', type: 'date'},
{label: 'Production', type: 'number'}
],
rows: [{c:[{v: new Date(2015, 3, 18)},
{v: 76}
]},
{c:[{v: new Date(2015, 3, 17)},
{v: 75}
]},
{c:[{v: new Date(2015, 3, 16)},
{v: 74}
]},
{c:[{v: new Date(2015, 3, 15)},
{v: 73}
]},
{c:[{v: new Date(2015, 3, 14)},
{v: 72}
]}
]
}
感謝,
我要補充一點,以上的JSON是通過訪問getdata.php輸出。再次感謝! – 2015-03-18 21:46:16