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(函数(){ $.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 } } } }); } });});问题:问题是图表中的数据没有显示。没有显示整个图表。使用 chrome 检查的日志:它说有一个错误:“未捕获的 ReferenceError:文本未定义”。
1 回答
万千封印
TA贡献1891条经验 获得超3个赞
这与 php、mysql 或 xampp 无关。您正在使用一个名为 的未定义方法text
。错误消息说明了一切。检查 ajax 成功中的第三行和第四行。你有:
var activeData = text(data.active);
将其替换为:
var activeData = data.active;
看看会发生什么。
- 1 回答
- 0 关注
- 116 浏览
添加回答
举报
0/150
提交
取消