1
我一直試圖讓一些谷歌圖表工作從本地數據庫的一些數據。我想我現在已經正確地出現了JSON。谷歌圖表顯示空白使用JSON
{
"cols": [
{
"id": "",
"label": "Inits",
"pattern": "",
"type": "string"
},
{
"id": "",
"label": "SalesVal",
"pattern": "",
"type": "number"
}
],
"rows": [
{
"c": [
{
"v": "IS",
"f": null
},
{
"v": "1708.6000",
"f": null
}
]
},
{
"c": [
{
"v": "NS",
"f": null
},
{
"v": "1098.8200",
"f": null
}
]
},
{
"c": [
{
"v": "RC",
"f": null
},
{
"v": "458.8200",
"f": null
}
]
}
]
}
而我正在使用它作爲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>
我已經過了幾次,不能看到我出錯的地方。
真棒。得到它返回一個數字,而不是字符串,它直線上升。非常感謝解釋。 – user3572565
太棒了,很高興這幫了你:) –