我需要幫助我的谷歌圖表...我目前有一個getdata.php有一個查詢與我的數據庫表中的信息..我有一個頁面,使人們可以選擇一個特定的用戶,一旦用戶被選中,我使用_GET選項來獲得一個ID並將其提供給getData.php中的查詢,以便它的動態生成圖表,最終產品/圖表不會被顯示,因爲我有一個沒有列消息..這裏是我的getData.php和chart1.php顯示圖表。表沒有列在谷歌圖表和PHP
chart1.php
<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?",
type: "GET" , // or GET, depends on your choice data
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.BarChart(document
.getElementById('chart_div'));
chart.draw(data);
}
訪問getdata.php
if(isset($_SESSION['userid'])){
$getid = $_GET['id'];
$graphquery =" SELECT sa.userid
,q.question_group_id
,sum(pa.answer)/(select count(q.question)*3)*100 as 'Percentage'
FROM surveyanswers sa
INNER JOIN possibleanswers pa
ON pa.possible_answer_id = sa.answer_voted
INNER JOIN questions q
ON q.question_id = sa.question_id
WHERE userid='$getid'
GROUP BY question_group_id";
$result_set=mysql_query($graphquery, $connection);
echo '{
"cols": [
{"id":"","label":"Groupname","pattern":"","type":"string"},
{"id":"","label":"Percentage","pattern":"","type":"number"}
],
"rows": [';
while($row =mysql_fetch_assoc($result_set)){
echo '{"c":[{"v":"'.$row['question_group_id'].'"},{"v":'.$row['Percentage'].'}]},';
}
echo ' ]
}';
}
如果您運行本身的select語句,你得到任何結果? – dstudeba
這jsFiddle與靜態數據一起工作,所以必須有數據庫查詢或ajax調用有問題:https://jsfiddle.net/phcbo1vr/4/ –
是@TheGunner,問題是在內部連接查詢時,我給在圖表生成的數據庫上的一個隨機用戶ID ...我的問題是,我不想有固定值的查詢這就是爲什麼我使用$ _GET [ID] ...我的JSON不是gwtting查詢結果,但我不知道我做了什麼錯誤 –