-
Notifications
You must be signed in to change notification settings - Fork 3
/
example-highcharts.html
163 lines (140 loc) · 5.5 KB
/
example-highcharts.html
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
<html>
<head>
<script
src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<script src="https://use.fontawesome.com/1ea8d4d975.js"></script>
<script src='../dist/bouquet.js'></script>
<style>
body {
margin: 5px;
}
* {
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
color: #666;
}
#container {
min-width: 310px;
width: 100%;
margin: 0 auto
}
</style>
</html>
</head>
<body>
<h1>
<a href="https://openbouquet.io/bouquet-demo-ob" target="_parent">Bouquet API</a> demo using HighCharts.js
</h1>
<div id="status"></div>
<div id="apiUrl"> </div>
<hr>
<div id="container" style="height: 400px;"></div>
<hr>
<script>
/*
demo using Bouquet analytics API with HighCharts to display data distribution by event category.
*/
var bouquet = new Bouquet({
url : '//demo.openbouquet.io/release/v4.2',
clientId : 'api-key-client',
apiKey : 'eyJhbGciOiJSUzI1NiJ9.eyJpc3MiOiJhcGkta2V5LWNsaWVudCIsInN1YiI6IjU4YWM1Y2FiMTVhYmNjMTJiYjUwYTU0MCIsInVzZXJFbWFpbCI6ImRlbW9AbG9jYWxob3N0LmNvbSIsImN1c3RvbWVySWQiOiI1OGFjNTNjMDE1YWJjYzEyYmI1MGE0NWIiLCJqdGkiOiJnTmF3dHdiZzRaYXRtQ1JXVVRQYnFnIiwiZXhwIjo0NjQxNTM0NTE5LCJpYXQiOjE0ODc5MzQ1MTksIm5iZiI6MTQ4NzkzNDM5OX0.g5f1DHxESj9PvC5meP8UKXmcZzbGZIiW-qwZ7mNAZWTlMlaAdIn1EBOZzB9oAwHzQxS0qez0iRDac874YCmnHrwYI8kgVoJQvbbJedKIJjfP_V_ZPvMiAfsX0wqeCmqG4_uXZoAh_sumvyDkKGfzutAfpR3DCVkWTqfYZ-iornkyYwH89Yqe_yBNQPO4pXpf3Dg68BlruZqc-tiow3ytynyxuEYEOPYIuyRL-fLpjNstRGa_gXIQYBx9v1yVGlZsQFVviJ5PMbCgIduM36g5leA_IXprw46KxjH_snbnEvAHypZCwhNaJJxlLGBEWTMnFKqytR68CGURskRM2D0VPQ'
});
// running query
$('#apiUrl').text('requesting data').append($('<i class="fa fa-refresh fa-spin fa-fw"></i>'));
bouquet.request("/analytics/@'5899bc6715abcc6bed69d766'.@bookmark:'58a5dc6b45d778b2bdb231c9'/query?period=%27Saletime%27&timeframe=2008-01-01&timeframe=2008-03-31&groupBy=to_date%28__PERIOD%29+as+%27period%27&groupBy=%27Event+%3E++Category+%3E++Catname%27+as+%27series%27&metrics=%27Total+quantity+sold%27&orderBy=asc%28to_date%28__PERIOD%29%29&limit=1000&offset=0&beyondLimit=0&envelope=data&data=RECORDS")
.then(function(res) {
displayChart(transformData(res));
})
.catch(function(err) {
$('#apiUrl').text('request failed: '+err+"("+err.code+")")
});
// HighCharts display function
function displayChart(data) {
$('#apiUrl')
.text('')
.append($('<a href="'+apiUrl+'&style=HTML" target="_blank">View data in Bouquet API explorer <i class="fa fa-external-link"></i></a>'));
if (!Highcharts.theme) {
Highcharts.setOptions({
colors : [ '#00505b', '#00aa9e', '#c74150', '#ff7c46',
'#ffcb4d' ]
});
}
Highcharts.chart('container', {
chart : {
type : 'area'
},
title : {
text : 'TIckets sold by event category'
},
subtitle : {
text : 'Tickit database'
},
xAxis : {
type : 'datetime',
units : [ [ 'month' ] ]
},
yAxis : {
title : {
text : 'Total quantity sold'
}
},
tooltip : {
split : true
},
legend : {
layout : 'vertical',
align : 'right',
verticalAlign : 'middle',
name : 'event category'
},
plotOptions : {
area : {
stacking : 'normal',
lineColor : '#444444',
lineWidth : 1,
marker : {
enabled : false,
symbol : 'circle',
radius : 2,
states : {
hover : {
enabled : true
}
}
}
}
},
series : data
});
}
// convert table data to HighCharts series
function transformData(data) {
var lookup = [];
data.forEach(function(record) {
if (lookup[record.series] === undefined) {
lookup[record.series] = {
name : record.series,
data : [],
total : 0
};
}
var date = Date.parse(record.period);
lookup[record.series].data.push({
x : date,
y : record["Total quantity sold"]
});
lookup[record.series].total += record["Total quantity sold"];
});
var series = [];
for ( var key in lookup) {
series.push(lookup[key]);
}
;
series.sort(function(a, b) {
return a.total - b.total
});
return series;
}
</script>
</body>