-
Notifications
You must be signed in to change notification settings - Fork 0
/
graph_2.php
55 lines (43 loc) · 1.33 KB
/
graph_2.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
<?php
$temp = 1;
function setTemp($pos)
{
$GLOBALS['temp'] = $pos;
}
function drawGraph()
{
echo"<div id=\"piechart\"></div>";
echo"<script type=\"text/javascript\" src=\"https://www.gstatic.com/charts/loader.js\"></script>";
require_once('classes/result.php');
$obj = new Result();
$result = $obj->count_vote();
echo "<script>";
echo "google.charts.load('current', {'packages':['corechart']});";
// Draw the chart and set the chart values
echo "function drawChart() { ".
" var data = google.visualization.arrayToDataTable([ ";
echo "['Task', 'Hours per Day'], ";
foreach($result as $ans){
if($ans[1] == $GLOBALS['temp'])
{
echo "['".$ans[2]."',". $ans[3]."],";
}
// "['Eat', 2],".
// "['TV', 4],".
// "['Gym', 2],".
// "['Sleep', 8]".
}
echo " ]);";
// Optional; add a title and set the width and height of the chart
echo "var options = {'title':'', 'width':550, 'height':400};".
// Display the chart inside the <div> element with id="piechart"
"var chart = new google.visualization.PieChart(document.getElementById('piechart'));".
"chart.draw(data, options);".
"}";
echo "google.charts.setOnLoadCallback(drawChart);";
echo "</script>";
}
?>
<!-- <script type="text/javascript"> -->
<!-- // Load google charts -->
<!-- </script> -->