forked from blacklabel/grouped_categories
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
261 lines (224 loc) · 6.52 KB
/
index.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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">
<link rel="stylesheet" charset="utf-8" type="text/css" href="./css/styles.css"/>
<title>Grouped Categories - Highcharts module</title>
<script src="https://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="https://code.highcharts.com/js/highcharts.js"></script>
<script src="./grouped-categories.js"></script>
</head>
<body>
<div id="main-content">
<script>
Highcharts.setOptions({
chart: {
borderWidth: 5,
borderColor: '#e8eaeb',
borderRadius: 0,
backgroundColor: '#f7f7f7'
},
title: {
style: {
'fontSize': '1em'
},
useHTML: true,
x: -10,
y: 8,
text: '<span class="chart-title"> Grouped categories <span class="chart-href"> <a href="https://www.blacklabel.pl" target="_blank"> Black Label </a> </span> <span class="chart-subtitle">plugin by </span></span>'
}
});
</script>
<h1>Grouped Categories - Highcharts module</h1>
<p>Go to project page to see this module in action: <a href="https://blacklabel.github.io/grouped_categories/">https://blacklabel.github.io/grouped_categories/</a></p>
<div class="chart-container" id="chart"></div>
<script>
window.chart = new Highcharts.Chart({
chart: {
renderTo: "chart",
type: "column"
},
series: [{
data: [4, 14, 18, 5, 6, 5, 14, 15, 18]
}],
xAxis: {
categories: [{
name: "Fruit",
categories: ["Apple", "Banana", "Orange"]
}, {
name: "Vegetable",
categories: ["Carrot", "Potato", "Tomato"]
}, {
name: "Fish",
categories: ["Cod", "Salmon", "Tuna"]
}]
}
});
</script>
<h3>Requirements</h3>
<ul>
<li>Plugin requires the latest Highcharts (tested with 2.3.5)</li>
</ul>
<h3>Installation</h3>
<ul>
<li>Like any other Highcharts module (e.g. exporting), add <code><script></code> tag pointing to <code>grouped-categories.js</code> below Highcharts script tag.</li>
<li>For NPM users:
<pre><code>var Highcharts = require('highcharts'),
require('grouped-categories')(Highcharts);
</code></pre></li>
</ul>
<h3>Usage and demos</h3>
<p>It's quite simple and intuitive, just pass object as category:</p>
<pre><code>xAxis: {
categories: [{
name: "Fruit",
categories: ["Apple", "Banana", "Orange"]
}, {
name: "Vegetable",
categories: ["Carrot", "Potato", "Tomato"]
}, {
name: "Fish",
categories: ["Cod", "Salmon", "Tuna"]
}]
}
</code></pre>
<div class="chart-container" id="chart-basic"></div>
<script>
window.chart = new Highcharts.Chart({
chart: {
renderTo: "chart-basic",
type: "column"
},
series: [{
data: [4, 14, 18, 5, 6, 5, 14, 15, 18]
}],
xAxis: {
categories: [{
name: "Fruit",
categories: ["Apple", "Banana", "Orange"]
}, {
name: "Vegetable",
categories: ["Carrot", "Potato", "Tomato"]
}, {
name: "Fish",
categories: ["Cod", "Salmon", "Tuna"]
}]
}
});
</script>
<p>You can also define more category levels:</p>
<pre><code>xAxis: {
categories: [{
name: "America",
categories: [{
name: "USA",
categories: ["New York", "San Francisco"]
}, {
name: "Canada",
categories: ["Toronto", "Vancouver"]
}, {
name: "Mexico",
categories: ["Acapulco", "Leon"]
}]
}, {
name: "Europe",
categories: [{
name: "United Kingdom",
categories: ["London", "Liverpool"]
}, {
name: "France",
categories: ["Paris", "Marseille"]
}, {
name: "Germany",
categories: ["Berlin", "Munich"]
}]
}]
}
</code></pre>
<div class="chart-container" id="chart-more"></div>
<script>
window.chart = new Highcharts.Chart({
chart: {
renderTo: "chart-more",
type: "column"
},
series: [{
data: [19, 6, 2, 1, 9, 4, 15, 2, 9, 11, 16, 18]
}],
xAxis: {
categories: [{
name: "America",
categories: [{
name: "USA",
categories: ["New York", "San Francisco"]
}, {
name: "Canada",
categories: ["Toronto", "Vancouver"]
}, {
name: "Mexico",
categories: ["Acapulco", "Leon"]
}]
}, {
name: "Europe",
categories: [{
name: "United Kingdom",
categories: ["London", "Liverpool"]
}, {
name: "France",
categories: ["Paris", "Marseille"]
}, {
name: "Germany",
categories: ["Berlin", "Munich"]
}]
}]
}
});
</script>
<p>For each level you can define subset of styling options. 0-level categories are based on the default Highcharts options.</p>
<pre><code>
xAxis: {
labels: {
groupedOptions: [{
style: {
color: 'red' // set red font for labels in 1st-Level
}
}, {
rotation: -45, // rotate labels for a 2nd-level
align: 'right'
}],
rotation: 0 // 0-level options aren't changed, use them as always
},
categories: [{
name: "America",
categories: [{
name: "USA",
categories: ["New York", "San Francisco"]
}, {
name: "Canada",
categories: ["Toronto", "Vancouver"]
}, {
name: "Mexico",
categories: ["Acapulco", "Leon"]
}]
}, {
name: "Europe",
categories: [{
name: "United Kingdom",
categories: ["London", "Liverpool"]
}, {
name: "France",
categories: ["Paris", "Marseille"]
}, {
name: "Germany",
categories: ["Berlin", "Munich"]
}]
}]
}
</pre></code>
<h3>Code</h3>
<p>The latest code is available on github: <a href="https://github.com/blacklabel/grouped_categories/">https://github.com/blacklabel/grouped_categories/</a></p>
<h3>Demo</h3>
<p>Demos are available at project's github page: <a href="https://blacklabel.github.io/grouped_categories/">https://blacklabel.github.io/grouped_categories/</a></p>
</body>
</html>