PHP:chart_db.php<?phprequire_once ('dbh.inc.php');$JSON_Response = array();//Counts the number of Active$count_active = mysqli_query($db, "SELECT client_id FROM client WHERE status = 1");$JSON_Response['active'] = mysqli_num_rows($count_active);//Counts the number of Inactive$count_inactive = mysqli_query($db, "SELECT client_id FROM client WHERE status = 0");$JSON_Response['inactive'] = mysqli_num_rows($count_inactive);error_log('hello');echo json_encode($JSON_Response);?>JS: chart.js $(文檔).ready(函數(shù)(){ $.ajax({ url:"http://localhost/FAME/private/includes/chart_db.php", method: "GET", success: function(response){ var data = JSON.parse(response); var activeData = text(data.active); var inactiveData = text(data.inactive); console.log(activeData); var ctx = document.getElementById('piechart').getContext('2d'); var statusChart = new Chart(ctx, { type: 'doughnut', data: { labels: ['Active', 'Inactive'], datasets: [{ pointStyle: 'circle', backgroundColor: [ 'rgb(78, 115, 223)', 'rgb(25, 179, 211)' ], data: activeData, inactiveData }] }, options: { responsive: true, maintainAspectRatio: false, segmentShowStroke: false, cutoutPercentage: 70, legend: { onClick: false, position: 'bottom', labels: { usePointStyle: true } } } }); } });});問題:問題是圖表中的數(shù)據(jù)沒有顯示。沒有顯示整個(gè)圖表。使用 chrome 檢查的日志:它說有一個(gè)錯(cuò)誤:“未捕獲的 ReferenceError:文本未定義”。
1 回答

萬千封印
TA貢獻(xiàn)1891條經(jīng)驗(yàn) 獲得超3個(gè)贊
這與 php、mysql 或 xampp 無關(guān)。您正在使用一個(gè)名為 的未定義方法text
。錯(cuò)誤消息說明了一切。檢查 ajax 成功中的第三行和第四行。你有:
var activeData = text(data.active);
將其替換為:
var activeData = data.active;
看看會(huì)發(fā)生什么。
- 1 回答
- 0 關(guān)注
- 147 瀏覽
添加回答
舉報(bào)
0/150
提交
取消