forked from stefanidisgeorge/watt_metter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchartday.php
81 lines (75 loc) · 2.3 KB
/
chartday.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
<?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;
$array1 = array();
$array2 = array();
$SQLGetLogs = $odb->query("SELECT * FROM `stats` ORDER BY `id` DESC Limit 168");
while ($getInfo = $SQLGetLogs->fetch(PDO::FETCH_ASSOC)) {
//$id=$getInfo['id'];
$lastdate = $getInfo['date'];
$datenumber = substr($lastdate, 0, -6);
$monthnumber = substr($lastdate, 2);
$monthnumber = substr($monthnumber, 0, -4);
$watt = $getInfo['sum'];
$counter = $getInfo['counter'];
if ($monthnumber == $month) {
if (array_key_exists($datenumber, $array1)) {
$array1[$datenumber] = $array1[$datenumber] + $watt;
$array2[$datenumber] = $array2[$datenumber] + $counter;
} else {
$array1[$datenumber] = $watt;
$array2[$datenumber] = $counter;
}
}
}
ksort($array1);
ksort($array2);
foreach ($array2 as $key => $val) {
$array1[$key] = $array1[$key] / $val;
}
?>
<script>
$(function () {
$('#container1').highcharts({
title: {
text: 'Daily Average Watt Consumption',
x: -20 //center
},
xAxis: {
categories: [<?php foreach ($array1 as $key => $val) { echo '\''.$key.'\',';} ?>]
},
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 ($array1 as $key => $val) { echo ''.$val.',';} ?>]
}]
});
});
</script>
<div id="container1" style="min-width: 310px; height: 400px; margin: 0 auto"></div>