-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatefetchplot.php
More file actions
119 lines (102 loc) · 2.7 KB
/
datefetchplot.php
File metadata and controls
119 lines (102 loc) · 2.7 KB
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<?php
////////////////////////////////////// initialise sql variables/////////////////////////////////
$servername = "localhost";
$username = "admin";
$password = "Jayant*1";
$dbname = "NMRL";
////////////Variable list///////////////////////////
$i=0;
$xarray[]=array();
$yarray[]=array();
$zarray[]=array();
$time[]=array();
////////////////////////////////////ask for max date////////////////////////////
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error)
{
die("Connection failed: " . $conn->connect_error);
}
$sql= "SELECT MAX(date1) FROM tilt";
$result = $conn->query($sql);
$max_public_date = mysqli_fetch_row($result);
$last_date = $max_public_date[0];
//echo "Latest entry is of the date ".$last_date;
$sql = "SELECT time1,x,y,z FROM tilt WHERE date1 = $last_date";
$i=0;
$result = $conn->query($sql);
if ($result->num_rows > 0)
{
// output data of each row
while($row = $result->fetch_assoc())
{
$xarray[$i]=$row["x"];
$yarray[$i]=$row["y"];
$zarray[$i]=$row["z"];
$time[$i]=$row["time1"];
$i++;
}
}
else
{
echo " 0 results for array ";
echo $sql;
}
echo "<br>";
//var_dump($xarray);
//echo "<br>";
//var_dump($time);
//echo "<br>";
/////////////////////////making a graph //////////////////////////////
?>
<html>
<body>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
google.charts.load('current', {'packages':['line']});
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
var data = new google.visualization.DataTable();
data.addColumn('number', 'Time of Day');
data.addColumn('number', 'X axis');
data.addColumn('number', 'Y axis');
data.addColumn('number','Z axis');
data.addRows([
<?php
$i=0;
$timel=sizeof($time);
for ($i =0;$i<$timel;$i++)
{
echo "[";
echo $time[$i]/100;
echo ", ";
echo $xarray[$i];
echo ", ";
echo $yarray[$i];
echo ", ";
echo $zarray[$i];
echo "],";
}
?>
]);
var options = {
chart: {
title: 'Daily analysis',
subtitle: 'The plot below shows variance in the X, Y and Z axes'
},
width: 900,
height: 500,
axes: {
x: {
0: {side: 'top'}
}
}
};
var chart = new google.charts.Line(document.getElementById('line_top_x'));
chart.draw(data, google.charts.Line.convertOptions(options));
}
</script>
<div id="line_top_x"></div>
<p style="color: red;">Test Message</p>
</body>
</html>