1 回答
TA贡献1817条经验 获得超6个赞
不要自己生成json。json_encode 始终使用:
<?php
$query = "SELECT name, score FROM `Users` order by score desc limit 5";
$result = mysqli_query($conn, $query);
$chartData = [
['Task', 'Hours per Day'],
];
if ($result->num_rows > 0) {
while($row = mysqli_fetch_array($result))
{
$chartData[] = [$row['name'], $row['score']];
}
}?>
<script type="text/javascript">
google.charts.load('current', {'packages':['corechart']});
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable(<?php echo json_encode($chartData)?>);
var options = {
title: 'My Daily Activities'
};
var chart = new google.visualization.PieChart(document.getElementById('piechart'));
chart.draw(data, options);
}
</script>
- 1 回答
- 0 关注
- 70 浏览
添加回答
举报