-
Notifications
You must be signed in to change notification settings - Fork 0
/
data3.php
87 lines (69 loc) · 2.41 KB
/
data3.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
<?php
// koneksi database
$konek = mysqli_connect("localhost", "root" ,"", "companyprofile");
// baca data dari tabel tb_sensor
// baca ID tertinggi
$sql_ID = mysqli_query($konek, "SELECT MAX(ID) FROM iot_tb");
//tanggap datanya
$data_ID = mysqli_fetch_array($sql_ID);
// ambil ID terakhir / terbesar
$ID_akhir = $data_ID['MAX(ID)'];
$ID_awal = $ID_akhir - 4 ;
// baca informasi tanggal untuk 5 data terakhir - sumbu x di grafik
$waktu = mysqli_query($konek, "SELECT waktu from iot_tb WHERE ID>='$ID_awal' and ID<='$ID_akhir' ORDER BY ID ASC ");
// baca informasi tegangan masuk untuk 5 data terakhir - sumbu y di grafik
$tegangan_in = mysqli_query($konek, "SELECT tegangan_in from iot_tb WHERE ID>='$ID_awal' and ID<='$ID_akhir' ORDER BY ID ASC ");
?>
<!-- tampilan grafik -->
<div class= "panel panel-primary">
<div class= "panel-heading" style="background-color:cadetblue">
Grafik Sensor
</div>
<div class="panel-body">
<!-- canvas untuk grafik -->
<canvas id= "myChart3"></canvas>
<!-- gambar grafik -->
<script type="text/javascript">
// baca ID canvas tempat grafik akan diletakkan
var canvas = document.getElementById('myChart3');
// letakkan data tanggal dan tegangan untuk grafik
var data = {
labels : [
<?php
while($data_tanggal = mysqli_fetch_array($waktu))
{
echo '"'.$data_tanggal['waktu']. '",'; //["25-04-20222", "26-04-2022"]
}
?>
] ,
datasets : [
{
label : "tegangan_in",
fill : true,
backgroundColor : "rgba(52, 231, 43, .2)",
borderColor : "rgba(52, 231, 43, 0.5)",
pointRadius : 5,
data : [
<?php
while($data_tegangan_in = mysqli_fetch_array($tegangan_in))
{
echo $data_tegangan_in['tegangan_in']. ',' ;
}
?>
]
}
]
};
//option grafik
var option = {
showLines : true,
animation : {duration : 0}
};
// cetak grafik kedalam canvas
var myLineChart = Chart.Line(canvas, {
data : data,
options : option
});
</script>
</div>
</div>