-
Notifications
You must be signed in to change notification settings - Fork 7
/
chart-functions.php
146 lines (97 loc) · 3.19 KB
/
chart-functions.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
<?php
function show_chart( $args ){
?>
<div id="<?php echo $args['container_id']; ?>" style="height: 400px; min-width: 310px; width: 100%; margin-bottom: 40px;"></div>
<script>
jQuery.noConflict();
var example = 'compare',
theme = 'default';
(function($){ // encapsulate jQuery
var seriesOptions = [],
seriesCounter = 0,
names = [<?php
foreach ( $args[ 'params' ] as $param ){
echo "'" . $param[ 'name' ] . "',";
}
?>];
var multi_array=new Array();
<?php
foreach ( $args[ 'params' ] as $param ){
echo "\nvar processed_" . $param[ 'json_id' ] ." = new Array();";
}
?>
$.getJSON('https://byteball.fr/<?php echo $args['json']; ?>', function(data) {
// Populate series
for (i = 0; i < data.length; i++){
<?php
foreach ( $args[ 'params' ] as $param ){
echo "\nprocessed_" . $param[ 'json_id' ] .".push([data[i].t, data[i]." . $param[ 'json_id' ] ."]);";
}
?>
}
<?php
foreach ( $args[ 'params' ] as $param ){
echo "\nmulti_array.push(processed_" . $param[ 'json_id' ] .");";
}
?>
/**
* Create the chart when all data is loaded
* @returns {undefined}
*/
function createChart() {
Highcharts.stockChart('<?php echo $args['container_id']; ?>', {
title: {
text: '<?php echo $args['title']; ?>'
},
subtitle: {
text: '<?php echo $args['subtitle']; ?>'
},
credits: {
enabled: true,
text: 'Credit: byteball.fr',
href: "https://byteball.fr",
},
rangeSelector: {
selected: 4
},
yAxis: {
labels: {
},
plotLines: [{
value: 0,
width: 2,
color: 'silver'
}]
},
plotOptions: {
series: {
compare: '<?php echo $args[ 'plotOptions_compare' ]; ?>',
showInNavigator: true
}
},
tooltip: {
pointFormat: '<?php echo $args[ 'tooltip_pointFormat' ]; ?>',
valueDecimals: <?php echo $args[ 'tooltip_valueDecimals' ]; ?>,
split: <?php echo $args[ 'tooltip_split' ]; ?>
},
series: seriesOptions
});
}
$.each(names, function (i, name) {
seriesOptions[i] = {
name: name,
data: multi_array[i],
};
//window.alert(i);
// As we're loading the data asynchronously, we don't know what order it will arrive. So
// we keep a counter and create the chart when all the data is loaded.
seriesCounter += 1;
if (seriesCounter === names.length) {
createChart();
}
});
}); })(jQuery);
</script>
<?php
}
?>