This repository has been archived by the owner on Nov 13, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
mostrecent.php
99 lines (76 loc) · 1.98 KB
/
mostrecent.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php
function mostrecent($id)
{
$sql = mysql_query("SELECT * FROM charts WHERE id='$id'");
$row =mysql_fetch_array($sql);
$type=$row['type'];
$title=$row['title'];
$label1=$row['label1'];
$label2=$row['label2'];
$dataset=$row['dataset'];
$sql3 = mysql_query("SELECT * FROM datasets WHERE id='$dataset'");
$row3 =mysql_fetch_array($sql3);
$table=$row3['table'];
$data = array();
//piechart
if($type=='PieChart')
{
$data[]= "['$label1', '$label2']";
$sql2 = mysql_query("SELECT * FROM $table");
while($row2=mysql_fetch_array($sql2))
{
$data[]="['".$row2[$label1]."', ".$row2[$label2]."]";
}
}
//linechart
else //if($type=='LineChart')
{
$label3 = $label2;
$total = substr_count($label2, ',');
$label2 = explode(',', $label2);
$total = $total+1;
$labels=array();
for($i=0;$i<$total;$i++)
{
$labels[]="'".$label2[$i]."'";
}
$labels=implode(', ', $labels);
$data[]= "['$label1', $labels]";
$sql2 = mysql_query("SELECT * FROM $table");
$total = substr_count($label3, ',');
$label3 = explode(',', $label3);
$total = $total+1;
while($row2=mysql_fetch_array($sql2))
{
$rowf=array();
for($i=0;$i<$total;$i++)
{
$rowf[]=$row2[$label3[$i]];
}
$rowf=implode(', ', $rowf);
$data[]="['".$row2[$label1]."', $rowf]";
}
}
$data =implode(', ', $data);
?>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("visualization", "1", {packages:["corechart"]});
google.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
<?php echo $data;?>
]);
var options = {
<?php
echo "title:'".$title."'";
?>
};
var chart = new google.visualization.<?php echo $type;?>(document.getElementById('chart_div<?php echo $id?>'));
chart.draw(data, options);
}
</script>
<div id="chart_div<?php echo $id?>" style="width: 100%; height: 300px;"></div>
<?php
}
?>