-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.php
92 lines (86 loc) · 2.54 KB
/
example.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
<?php
include_once 'estimate.class.php';
// example array. we will be using the unix time stamp as the base for calculating Reading 1 and 2.
$array = array(
0 =>
array(
'Date' => '1346630400',
'Reading_1' => '10422',
'Reading_2' => '9456',
),
1 =>
array(
'Date' => '1350864000',
'Reading_1' => '10651',
'Reading_2' => '9551',
),
72 =>
array(
'Date' => '1351382400',
'Reading_1' => '10701',
'Reading_2' => '9564',
),
12 =>
array(
'Date' => '1366070400',
'Reading_1' => '13205',
'Reading_2' => '10336',
),
4 =>
array(
'Date' => '1367366400',
'Reading_1' => '13264',
'Reading_2' => '10370',
),
9 =>
array(
'Date' => '1369008000',
'Reading_1' => '13365',
'Reading_2' => '10418',
),
);
// create new object. the array and the key which we will use to calculate the estimates must be passed
$ele_est = new estimate($array, 'Date');
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
</head>
<body>
<?php
//loop through some random dates estmiating as we go
$unix = time();
for ($i = strtotime("-1 year", $unix); $unix > $i; $unix = strtotime("-1 month", $unix)) {
$ele_est->estimate('Date', $unix, 'Reading_1');
$ele_est->estimate('Date', $unix, 'Reading_2');
}
$data = $ele_est->sort_array($ele_est->estmated_output, 'Date');
// Now display the estimates on a chart
?>
<div id="ele_chart_div" style="width: 100%;"></div>
<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([
['Date', 'Reading 1', 'Reading 2']
<?php
foreach ($data as $value) {
echo ",['" . date("d.m.y",
$value['Date']) . "', " . $value['Reading_1'] . ", " . $value['Reading_2'] . "]\n";
}
?>
]);
var options = {
curveType: "function",
title: 'The Chart'
};
var chart = new google.visualization.LineChart(document.getElementById('ele_chart_div'));
chart.draw(data, options);
}
</script>
</body>
</html>