1
我是新的谷歌圖表API。我正在使用一些示例來創建帶有搜索功能的圖表,其中涉及XAMPP上的MySQL,但它只返回「選項部分」和「無數據」消息。爲什麼沒有數據信息顯示? (試圖創建谷歌圖表)
我測試了SQL查詢,它工作。
我的代碼:
<?php
include("config.php");
$query1 = "SELECT partido, COUNT(*) as num_faltas FROM reuniao WHERE presenca LIKE '%Injustific%' GROUP BY partido";
$query2 = "SELECT DISTINCT partido FROM reuniao";
$result1 = mysqli_query($conn, $query1);
while ($row = mysqli_fetch_array($result1)) {
echo "['" . $row['partido'] . "'," . $row['num_faltas'] . "],";
}
?>
<!DOCTYPE HTML>
<html>
<head>
<title> Graficos </title>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
// Load the Visualization API and the corechart package.
google.charts.load('current', {'packages': ['corechart']});
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
var data = new google.visualization.arrayToDataTable([
['Partido', 'Faltas injustificadas'],
<?php
while ($row = mysqli_fetch_array($result1)) {
echo "['" . $row['partido'] . "'," . $row['num_faltas'] . "],";
}
?>
]);
var options = {'title': 'Numero de Faltas injustificadas por Partido'};
var chart = new google.visualization.PieChart(document.getElementById('piechart'));
chart.draw(data, options);
}
</script>
</head>
<body>
<div style="width: 900px;">
<div id="piechart" style="width: 900px; height: 500px;"></div>
</div>
</body>
</html>
你能告訴你獲取完整的數據(數組或JSON) –
的例子很好的,同時在代碼中返回這個: ['CDS-PP',5],['PCP',1],['PS',3],['PSD',3], – VoltDamage
你想知道其餘的表中的數據「reuniao」? – VoltDamage