-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
114 lines (100 loc) · 1.89 KB
/
main.js
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
// Chart options
const options = {
chart: {
height: 450,
width: '100%',
type: 'bar',
background: '#192228',
foreColor: 'white'
},
series: [
{
name: 'Population',
data: [
1376048940,
1311050530,
325843650,
257563820,
207847530,
188924870,
182201960,
160995640,
143456920,
126573480
].map(x => x / 1000000)
}
],
xaxis: {
categories: [
'China',
'India',
'United States',
'Indonesia',
'Brazil',
'Pakistan',
'Nigeria',
'Bangladesh',
'Russia',
'Japan'
]
},
fill: {
colors: ['#a0ecff'] // bar-color
},
dataLabels: {
enabled: false
},
title: {
text: 'Top 10 Most Populous Countries',
align: 'center',
margin: 20,
offsetY: 20,
style: {
fontSize: '25px',
color: 'white'
}
},
tooltip: {
y: {
formatter: function(value) {
return value + ' million';
}
}
},
subtitle: {
text: '(in millions)',
align: 'center',
offsetY: 60,
floating: false,
style: {
fontSize: '18px',
color: 'white'
}
}
};
// Initialize and render chart
const chart = new ApexCharts(document.querySelector('#chart'), options);
chart.render();
// Holds the current orientation
let isVertical = true;
// Toggle the bar chart's orientation (Vertical <-> Horizontal)
document.getElementById('toggle').addEventListener('click', () => {
chart.updateOptions({
plotOptions: {
bar: {
horizontal: isVertical
}
}
});
isVertical = !isVertical;
toggleButton();
});
// Toggles the text for the button
const toggleButton = () => {
let button = document.getElementById('toggle');
if (button.innerHTML === 'Horizontal') {
button.innerHTML = 'Vertical';
} else {
button.innerHTML = 'Horizontal';
}
};