0
我花了一天嘗試餅圖的最好的部分,現在我有一個餅圖,它告訴我謊言!它說有一個系列,佔100%,這是不正確的!有人能告訴我我哪裏出錯了。谷歌圖表JSON調用可能的時間錯誤
到目前爲止,我有這樣的:
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js">
</script>
<script type="text/javascript" src="https://www.google.com/jsapi">
</script>
<script type="text/javascript">
google.load("visualization", "1", {packages:["corechart"]});
function drawChart() {
var jsonData = $.ajax({
url: "getdata_searches.php",
dataType:"json",
async: false
}).responseText;
// Create our data table out of JSON data loaded from server.
var data = new google.visualization.DataTable(jsonData);
var options = {
title: 'Searches By Type'
};
var chart = new google.visualization.PieChart(document.getElementById('piechart'));
chart.draw(data, options);
}
google.setOnLoadCallback(drawChart);
</script>
我getdata_searches.php文件是這樣:
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql="Select Other, Count(Other) As Count From activity WHERE tel = '0000' AND Other <> '' Group By Other Order By Count(Other) Desc;";
$result = $conn->query($sql);
$data = array('cols' => array(array('label' => 'Other', 'type' => 'string'),
array('label' => 'Count', 'type' => 'number')),
'rows' => array());
while ($row = $result->fetch_assoc()) {
$data['rows'][] = array('c' => array(array('v' => $row["Other"]), array('v' => $row["Count"])));
}
echo json_encode($data);
主要生產:
{
"cols":[
{"label":"Other","type":"string"},
{"label":"Count","type":"number"}],
"rows":[
{"c":[{"v":"AVS Search"},{"v":"215"}]},
{"c":[{"v":"Urgent Care Centres"},{"v":"50"}]},
{"c":[{"v":"Emer. Depts"},{"v":"37"}]},
{"c":[{"v":"Adult Trauma Networks"},{"v":"19"}]}
]
}
我已經走了一圈又一圈在這個圈子裏,我一定會錯過一些明顯的東西,請幫忙!
完美! ('''')),數組('v'=> $ row [「Count」 ]))));''''數據['rows'] [] = array('c'=> array(array''v'=> $ row [「Other」]),array('v'=> (int)$ row [「Count」])));'非常感謝 –