-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhighcharts.html
564 lines (522 loc) · 18.7 KB
/
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
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
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Visualization data using Highcharts</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="css/tui-chart.min.css">
<link rel="stylesheet" href="css/c3.min.css">
<link rel="stylesheet" href="css/highcharts.css">
<script src="js/jquery-3.3.1.min.js" type='text/javascript'></script>
<script type='text/javascript' src='js/tui-code-snippet.min.js'></script>
<script type='text/javascript' src='js/raphael.min.js'></script>
<script src="js/tui-chart.min.js"></script>
<script src="js/highcharts.js"></script>
<!-- This refernce file used for bubble chart-->
<script src="js/highcharts-more.js"></script>
<script src="js/d3.min.js" type='text/javascript'></script>
<script src="js/c3.min.js" type='text/javascript'></script>
<!--Chart.js-->
<script src="js/Chart.min.js"></script>
<script src="js/lodash.min.js"></script>
<script>
var topArticleData = [{
"category": "ASP.NET",
"url": "https://www.c-sharpcorner.com/technologies/asp-dot-net-programming",
"categoryData": [{
"categoryType": "Articles",
"count": "4256"
}, {
"categoryType": "Blogs",
"count": "1380"
}, {
"categoryType": "Links",
"count": "111"
}, {
"categoryType": "Videos",
"count": "77"
}, {
"categoryType": "News",
"count": "18"
}]
}, {
"category": "SharePoint",
"url": "https://www.c-sharpcorner.com/technologies/sharepoint",
"categoryData": [{
"categoryType": "Articles",
"count": "3944"
}, {
"categoryType": "Blogs",
"count": "2318"
}, {
"categoryType": "Links",
"count": "54"
}, {
"categoryType": "Videos",
"count": "37"
}, {
"categoryType": "News",
"count": "22"
}]
}, {
"category": "C#",
"url": "https://www.c-sharpcorner.com/technologies/csharp-programming",
"categoryData": [{
"categoryType": "Articles",
"count": "2567"
}, {
"categoryType": "Blogs",
"count": "1684"
}, {
"categoryType": "Links",
"count": "71"
}, {
"categoryType": "Videos",
"count": "98"
}, {
"categoryType": "News",
"count": "14"
}]
}, {
"category": "Azure",
"url": "https://www.c-sharpcorner.com/technologies/azure",
"categoryData": [{
"categoryType": "Articles",
"count": "1491"
}, {
"categoryType": "Blogs",
"count": "174"
}, {
"categoryType": "Links",
"count": "62"
}, {
"categoryType": "Videos",
"count": "90"
}, {
"categoryType": "News",
"count": "141"
}]
}, {
"category": "SQL Server",
"url": "https://www.c-sharpcorner.com/technologies/sql-server",
"categoryData": [{
"categoryType": "Articles",
"count": "1205"
}, {
"categoryType": "Blogs",
"count": "1175"
}, {
"categoryType": "Links",
"count": "62"
}, {
"categoryType": "Videos",
"count": "25"
}, {
"categoryType": "News",
"count": "25"
}]
}, {
"category": "Angular",
"url": "https://www.c-sharpcorner.com/technologies/angularjs",
"categoryData": [{
"categoryType": "Articles",
"count": "1000"
}, {
"categoryType": "Blogs",
"count": "269"
}, {
"categoryType": "Links",
"count": "14"
}, {
"categoryType": "Videos",
"count": "41"
}, {
"categoryType": "News",
"count": "14"
}]
}, {
"category": "Windows 10",
"url": "https://www.c-sharpcorner.com/technologies/windows_10",
"categoryData": [{
"categoryType": "Articles",
"count": "915"
}, {
"categoryType": "Blogs",
"count": "114"
}, {
"categoryType": "Links",
"count": "46"
}, {
"categoryType": "Videos",
"count": "24"
}, {
"categoryType": "News",
"count": "312"
}]
}, {
"category": "UWP",
"url": "https://www.c-sharpcorner.com/technologies/universal-windows-apps",
"categoryData": [{
"categoryType": "Articles",
"count": "887"
}, {
"categoryType": "Blogs",
"count": "86"
}, {
"categoryType": "Links",
"count": "28"
}, {
"categoryType": "Videos",
"count": "9"
}, {
"categoryType": "News",
"count": "18"
}]
}, {
"category": ".NET",
"url": "https://www.c-sharpcorner.com/technologies/dot_net_2015",
"categoryData": [{
"categoryType": "Articles",
"count": "818"
}, {
"categoryType": "Blogs",
"count": "710"
}, {
"categoryType": "Links",
"count": "332"
}, {
"categoryType": "Videos",
"count": "91"
}, {
"categoryType": "News",
"count": "93"
}]
}, {
"category": "Visual Studio",
"url": "https://www.c-sharpcorner.com/technologies/visual-studio",
"categoryData": [{
"categoryType": "Articles",
"count": "737"
}, {
"categoryType": "Blogs",
"count": "231"
}, {
"categoryType": "Links",
"count": "51"
}, {
"categoryType": "Videos",
"count": "73"
}, {
"categoryType": "News",
"count": "115"
}]
}];
</script>
<script>
//drawBarChartUsingTUILibrary({ id, chartTitle,datacategory,isColumnChart})
//Reusable utility function to draw tui bar or column charts
function drawBarChartUsingTUILibrary(options) {
// Common chartOption for Tui Charts
var chartOptions = {
chartExportMenu: {
visible: false // default is true.
},
chart: {
width: 470,
height: 250,
title: 'C-SharpCorner Articles Technology Category',
format: '1,000'
},
yAxis: {
title: 'Y Axis'
},
xAxis: {
title: 'X Axis',
min: 0,
//max: 9000,
// suffix: '$'
},
series: {
showLabel: true
}
};
//Sub Category
var categoryData = ["Articles", "Blogs", "Links", "Videos", "News"];
// Generate series data based on sub Category
var data = {
// categories: _.pluck(topData,'category'),
categories: [options.category],
series: _.map(options.data, function(e) {
//Calculate Article count in each category
var ele = _.find(e.categoryData, function(e) {
return e.categoryType === options.category ? e.count : 0;
});
return {
name: e.category,
data: [parseInt(ele.count)] // This format also works data: parseInt(ele.count)
};
})
};
//Update Json nested proprties using Lodash
_.set(chartOptions, "chart.title", options.chartTitle);
if (options.isColumnChart) {
//Draw tui Columns Charts
tui.chart.columnChart(document.getElementById(options.id), data, chartOptions);
} else {
//Draw tui Bar Charts
tui.chart.barChart(document.getElementById(options.id), data, chartOptions);
}
}
var drawBarChartUsingC3JSLibrary = function(options) {
// Generate series data based on sub Category
var columnNameArray = ["x", options.category]
var data = _.map(options.data, function(e) {
//Calculate Article count in each category
var ele = _.find(e.categoryData, function(e) {
return e.categoryType === options.category ? e.count : 0;
});
// For C3JS charts data should in column array
return [
e.category,
parseInt(ele.count)
];
});
//Concat Similar type or Array of array e.g. [['column1','column2']], [['C#',100],['Javascript',90]]
//Merge both array to single
data = _.concat([columnNameArray], data);
var chart = c3.generate({
bindto: '#' + options.id,
data: {
// 'x' For showing Title on Axis
x: 'x',
columns: data,
//x:'country',
//json:commonData,
//json:_.pluck(commonData,"data") ,
type: 'bar',
//Show label value on bar
labels: true
// keys: {
// // tick:{ value: _.pluck(commonData,"country")}
// }
},
axis: {
// 'x' must be set type 'category' to display category
x: {
type: 'category' // this needed to load string x value
},
rotated: options.isRotate,
y: {
inverted: false,
}
},
bar: {
width: {
ratio: 0.5 // this makes bar width 50% of length between ticks
}
// or
//width: 100 // this makes bar width 100px
},
grid: {
x: {
show: true
},
y: {
show: true
}
}
});
setTimeout(function() {
chart.resize();
}, 100);
};
function drawBarChartUsingHighchart(options) {
//Sub Category
// var categoryData = ["Articles", "Blogs", "Links", "Videos", "News"];
// Generate series data based on sub Category
var data = _.map(options.data, function(e) {
//Calculate Article count in each category
var ele = _.find(e.categoryData, function(e) {
return e.categoryType === options.category ? e.count : 0;
});
return {
name: e.category,
data: [parseInt(ele.count)] //Value must be wrapped in array
};
});
var chartOptions = {
chart: {
type: options.isColumnChart === undefined ? 'bar' : "column"
},
title: {
text: 'Historic World Population by Region'
},
subtitle: {
text: ''
},
xAxis: {
categories: [options.category],
// OLD way commnted and make dynamic based on base data
// ["cat1","cat2"]
title: {
text: null
}
},
yAxis: {
min: 0,
title: {
//text: 'Population (millions)',
align: 'high'
},
labels: {
overflow: 'justify'
}
},
tooltip: {
// valueSuffix: ' millions'
},
plotOptions: {
//Show label on bar charts
bar: {
dataLabels: {
enabled: true
}
},
//Show label on column charts
column: {
dataLabels: {
enabled: true
}
}
},
legend: {
// Commented below code due to Roate chart feature as this chart doesn't fit in available region
// layout: 'vertical',
// align: 'right',
// verticalAlign: 'top',
// x: -30,
// y: 50,
//floating: true,
borderWidth: 1,
backgroundColor: ((Highcharts.theme && Highcharts.theme.legendBackgroundColor) || '#FFFFFF'),
shadow: true
},
credits: {
enabled: false
},
//Pass series data as array of object
series: data
};
//Update Json nested proprties using Lodash
_.set(chartOptions, "title.text", options.chartTitle);
console.log(data)
//Draw bar charts using Highcharts
Highcharts.chart(options.id, chartOptions);
}
function drawBarChartUsingChartJS(options) {
var seriesData = _.map(options.data, function(e) {
var ele = _.find(e.categoryData, function(e) {
return e.categoryType === options.category ? e.count : 0;
});
return {
label: e.category,
data: [parseInt(ele.count)]
};
});
//For Chart.JS Charts Data and Label Naming convention should be in below formats
var data = {
labels: [options.category],
datasets: seriesData
}
var ChartOptions = {
scales: {
yAxes: [{
// stacked:true,
gridLines: {
display: true,
color: "rgba(255,99,132,0.2)"
}
}],
xAxes: [{
stacked: false,
gridLines: {
display: false
}
}]
}
};
var ctx = document.getElementById(options.id);
//console.log(ctx);
new Chart(ctx, {
type: options.isRotate === undefined ? "bar" : options.isRotate, //'bar',//'horizontalBar', for rotate charts
data: data,
options: ChartOptions
});
}
$(document).ready(function() {
console.log("Dom is ready, Now call function to draw charts");
drawBarChartUsingHighchart({
id: "tui-chart1",
chartTitle: 'C-SharpCorner Top 10 Contribution by Articles Count',
data: topArticleData,
category: "Articles"
});
drawBarChartUsingHighchart({
id: "tui-chart2",
chartTitle: 'C-SharpCorner Top 10 Contribution by Blogs Count',
data: topArticleData,
category: "Blogs"
});
drawBarChartUsingHighchart({
id: "tui-chart3",
chartTitle: 'C-SharpCorner Top 10 Contribution by News Count',
data: topArticleData,
category: "News",
isColumnChart: true
});
// Draw Bar charts using HighCharts Library
drawBarChartUsingHighchart({
id: "hc-chart1",
chartTitle: 'C-SharpCorner Top 10 Contribution by News Count',
data: topArticleData,
category: "News",
isColumnChart: true
});
// Draw Bar charts using C3js Library
drawBarChartUsingC3JSLibrary({
id: "c3-chart1",
chartTitle: 'C-SharpCorner Top 10 Contribution by News Count',
data: topArticleData,
category: "News",
isColumnChart: true
});
// Draw Bar charts using ChartJS Library
drawBarChartUsingChartJS({
id: "chart1",
chartTitle: 'C-SharpCorner Top 10 Contribution by News Count',
data: topArticleData,
category: "News",
isColumnChart: true
});
});
</script>
</head>
<body>
<h3>Sample TUI/HighCharts/C3/Chartjs Bar charts based on c-sharpcorner web scrapping data.</h3>
<div id="c3-chart1"></div>
<br />
<div id="hc-chart1"></div>
<br />
<div id="tui-chart1"></div>
<br />
<div id="tui-chart2"></div>
<br />
<div id="tui-chart3"></div>
<br />
<!-- Canvas or chart.js chart must be wrapped with its parent containing width or height-->
<div style="width:500px;height:350px;">
<canvas id="chart1" height="200px"></canvas>
</div>
</body>
</html>