-
Notifications
You must be signed in to change notification settings - Fork 10
/
piechart.php
72 lines (60 loc) · 1.89 KB
/
piechart.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
date_default_timezone_set('Europe/Dublin');
//include database connection
$conn= mysqli_connect("localhost", "root", "", "compsys");
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
//query all records from the database
/* For this to work I had to create a view in the database
* SELECT status, COUNT(status) AS total
FROM Repairs
WHERE month(repairDate) = EXTRACT(month FROM (NOW()))
GROUP BY status
ORDER BY repairDate DESC;
*/
$query = "select * from monthlyrepairs";
//execute the query
$result= mysqli_query($conn, $query);
//get number of rows returned
//$num_results = $result->num_rows;
if( mysqli_num_rows($result) > 0){
?>
<!-- load api -->
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript">
//load package
google.load('visualization', '1', {packages: ['corechart']});
</script>
<script type="text/javascript">
function drawVisualization() {
// Create and populate the data table.
var data = google.visualization.arrayToDataTable([
['Status', 'Total'],
<?php
while( $row = $result->fetch_assoc() ){
extract($row);
echo "['{$status}', {$total}],";
}
?>
]);
var options = {
title: '<?php echo "FROM " .date('01 F Y') ." until " .date('h:i:s a', time()) ." NOW."?>',
is3D: 'true',
pieSliceText: 'value',
slices: { 7: {offset: 0.2},
},
legend: {position: 'left', textStyle: {color: '#3f3f3f', fontSize: 12}}
};
// Create and draw the visualization.
new google.visualization.PieChart(document.getElementById('pie_chart')).
// {title:"<?php echo "FROM " .date('01 F Y') ." until " .date('h:i:s a', time()) ." NOW."?>"}
draw(data, options);
}
google.setOnLoadCallback(drawVisualization);
</script>
<?php
}else{
$title = "No programming languages found in the database.";
}
?>