-
Notifications
You must be signed in to change notification settings - Fork 1
/
charthour.php
74 lines (65 loc) · 2.04 KB
/
charthour.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
<?php
// Start MySQL Connection
include('dbconnect.php');
date_default_timezone_set('Europe/Athens');
$currentDate = date('d/m/Y H:i:s a');
$hour = $currentDate[11] . $currentDate[12];
$day = $currentDate[0] . $currentDate[1];
$month = $currentDate[3] . $currentDate[4];
$year = $currentDate[6] . $currentDate[7] . $currentDate[8] . $currentDate[9];
$date = $day . $month . $year;
$array = array();
$SQLGetLogs = $odb->query("SELECT * FROM `stats` ORDER BY `id` DESC Limit 48");
while ($getInfo = $SQLGetLogs->fetch(PDO::FETCH_ASSOC)) {
//$id=$getInfo['id'];
$lastdate = $getInfo['date'];
$datenumber = substr($lastdate, 0, -6);
$lasttime = $getInfo['time'];
$watt = $getInfo['sum'];
$counter = $getInfo['counter'];
if ($datenumber == $day) {
$array[$lasttime] = $watt / $counter;
}
}
asort($array);
?>
<script>
$(function () {
$('#container').highcharts({
title: {
text: 'Hourly Average Watt Consumption',
x: -20 //center
},
xAxis: {
categories: [<?php foreach ($array as $key => $val) { echo '\''.$key.':00\',';} ?>]
},
yAxis: {
title: {
text: 'Consumption (Watt)'
},
plotLines: [{
value: 0,
width: 1,
color: '#808080'
}]
},
tooltip: {
valueSuffix: ' Watt'
},
legend: {
layout: 'vertical',
align: 'right',
verticalAlign: 'middle',
borderWidth: 0
},
series: [{
showInLegend: false,
name: 'Consumption',
data: [<?php foreach ($array as $key => $val) { echo ''.number_format($val, 2, '.', ',').',';} ?>]
}]
});
});
</script>
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>