-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathchart.ajax.php
105 lines (77 loc) · 2.92 KB
/
chart.ajax.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
93
94
95
96
97
98
99
100
101
102
103
104
105
<?php
header('Access-Control-Allow-Methods: GET');
require('depedencies.inc.php');
// Query Data
if(isset($_GET['debug']) && $_GET['debug'] > 0) { $debug = (int) $_GET['debug']; }
else $debug = 0;
if(isset($_GET['unit']) && $_GET['unit'] != '') { $unit = $_GET['unit']; }
else $unit = '1m';
// Google Chart on History
$History = new History();
$History->selectChart($unit);
if($debug)
krumo($History);
if(isset($History->List) && is_array($History->List) && count($History->List) > 0) {
$i=0;
$googleChartData = array();
foreach($History->List as $id => $detail) {
$googleChartData[$i] = new stdClass();
$googleChartData[$i] = $detail;
$i++;
}
krsort($googleChartData);
$i=0;
$googleChartCols[$i] = new stdClass();
$googleChartCols[$i]->id = 'date';
$googleChartCols[$i]->label = 'Time';
if($unit == '12h')
$googleChartCols[$i]->type = 'date';
else
$googleChartCols[$i]->type = 'datetime';
$i++;
$googleChartCols[$i] = new stdClass();
$googleChartCols[$i]->id = 'price';
$googleChartCols[$i]->label = 'Price';
$googleChartCols[$i]->type = 'number';
$i=0;
foreach($googleChartData as $data) {
$addDate = strtotime($data->addDate);
$month = date('n', $addDate)-1;
$day = date('j', $addDate)-1;
$googleChartRows[$i]->c[0] = new stdClass();
$googleChartRows[$i]->c[0]->v = "Date(".date('Y', $addDate).",$month,$day,".date('H,i,s', $addDate).")";
$googleChartRows[$i]->c[0]->f = date('d/m/Y H:i', $addDate);
/*switch($unit) {
case '1m':
default:
$googleChartRows[$i]->c[0]->f = date('H:i', strtotime($data->addDate));
break;
case '5m':
$googleChartRows[$i]->c[0]->f = date('H:i', strtotime($data->addDate));
break;
case '15m':
$googleChartRows[$i]->c[0]->f = date('H:i', strtotime($data->addDate));
break;
case '30m':
$googleChartRows[$i]->c[0]->f = date('H:i', strtotime($data->addDate));
break;
case '1h':
$googleChartRows[$i]->c[0]->f = date('H:i', strtotime($data->addDate));
break;
case '4h':
$googleChartRows[$i]->c[0]->f = date('d/m H:i', strtotime($data->addDate));
break;
case '1d':
$googleChartRows[$i]->c[0]->f = date('d/m H:i', strtotime($data->addDate));
break;
} */
$googleChartRows[$i]->c[1] = new stdClass();
$googleChartRows[$i]->c[1]->v = $data->price;
$i++;
}
$googleChart = array('cols' => $googleChartCols, 'rows' => $googleChartRows);
if($debug)
krumo($googleChart);
echo json_encode($googleChart, JSON_UNESCAPED_SLASHES); //JSON_PRETTY_PRINT JSON_UNESCAPED_SLASHES
}
?>