我正在尝试创建基于mysql数据显示的饼图。但是当我添加<?php while ($s=$done->fetch()) {echo $s['count(*)'];} ?>
时,为什么我的Google饼图没有显示?如果我不添加它,饼图只是完美地显示它。
我尝试使用Google搜索,但似乎无法找到解决方案。谢谢你提前!
<?php
$db = new PDO('mysql:host=localhost;dbname:coits','root','');
$done = $db->query('SELECT COUNT(*) FROM coi_system WHERE month(todays_date) = EXTRACT(month FROM (NOW()))
AND year(todays_date) = EXTRACT(year FROM (NOW()))
AND CHAR_LENGTH(department)>0');
$notdone = $db->query('SELECT COUNT(*) FROM coi_system WHERE month(todays_date) = EXTRACT(month FROM (NOW()))
AND year(todays_date) = EXTRACT(year FROM (NOW()))
AND CHAR_LENGTH(department)<1');
?>
<!DOCTYPE html>
<html>
<head>
<head>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<meta charset="UTF-8">
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
google.charts.load('current', {'packages':['corechart']});
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
['Task', 'Hours per Day'],
['Updated', <?php while ($s=$done->fetch()) {echo $s['count(*)'];} ?>],
['Not updated', <?php while ($s=$notdone->fetch()) {echo $s['count(*)'];} ?>]
]);
var options = {
title: 'My Daily Activities'
};
var chart = new google.visualization.PieChart(document.getElementById('piechart'));
chart.draw(data, options);
}
</script>
<style>
body {
margin: 0;
font-family: Arial;
}
.topnav {
background-color: #e9e9e9;
padding: 10px;
display: flex;
flex-wrap: wrap;
align-items: center;
color: #18786E;
letter-spacing: 5px;
text-decoration: none;
}
.topnav a {
margin-left: auto;
margin-top: auto;
text-align: center;
border-style: outset;
font-size: 17px;
padding: 15px 20px;
color: black;
}
.btn_logout {
background-color: #18786E;
color: #e9e9e9;
margin-left: auto;
padding: 12px 20px;
}
.nav{
border:1px solid #ccc;
border-width:1px 0;
list-style:none;
margin:0;
padding:0;
text-align:center;
background-color: #137D72;
}
.nav li{
display:inline;
}
.nav a{
display:inline-block;
padding:5px;
color: #FAFBFB;
}
</style>
</head>
<body>
<div class="topnav">
<img src="HICOM LOGO.png" style="width:130px ;height:80px; margin-left: 30px;">
<label style="font-size: 36px; margin-bottom: 8px;">Cost Optimisation Initiatives System</label>
<form style="margin-left: auto;" method="post" action="logout.php">
<button class="btn_logout" id="submit" type="submit" >LogOut</button></form>
</div>
<ul class="nav">
<li><a href="admin_search.php">Update</a></li>
<li><a href="report_admin.php">Report</a></li>
</ul>
<br><br>
<div align="center">
<div id="piechart" style="width: 900px; height: 500px;"></div>
</div>
</html>
&#13;