HTMLcopy
1
<div id="container"></div>
CSScopy
8
1
html,
2
body,
3
#container {
4
width: 100%;
5
height: 100%;
6
margin: 0;
7
padding: 0;
8
}
JavaScriptcopy
x
1
anychart.onDocumentReady(function () {
2
// Create and return simple linear gauge
3
function drawGauge(value, settings) {
4
// Create gauge with settings
5
var gauge = anychart.gauges.linear();
6
gauge.data([value, settings.value]);
7
gauge.layout('horizontal');
8
9
// Set scale for gauge
10
var scale = anychart.scales.linear();
11
12
scale.minimum(0).maximum(settings.maximum).ticks({ interval: 2 });
13
14
// Set axis for gauge
15
var axis = gauge.axis(0);
16
axis.width('1%').offset('43%').scale(scale).orientation('bottom');
17
18
// Set the axis label format
19
axis.labels().format('{%Value}%').fontSize('10px');
20
21
// Create and set bar point
22
var barSeries = gauge.bar(0);
23
barSeries
24
.scale(scale)
25
.width('4%')
26
.fill('#296953')
27
.stroke('#296953');
28
29
// Create and set LED point
30
var ledPointer = gauge.led(1);
31
ledPointer
32
.offset('10%')
33
.width('30%')
34
.count(settings.maximum)
35
.scale(scale)
36
.gap(0.55)
37
.dimmer(function () {
38
return '#eee';
39
});
40
ledPointer.colorScale().colors(['#63b39b', '#63b39b']);
41
42
// Create and set label with actual data
43
var labelBar = barSeries.labels();
44
labelBar
45
.enabled(true)
46
.offsetY('-15px')
47
.fontColor('#455a64')
48
.fontSize('12px')
49
.fontWeight(600)
50
.format('{%Value} %');
51
52
// Set gauge tooltip
53
gauge
54
.tooltip()
55
.useHtml(true)
56
.titleFormat('{%Value} %')
57
.format(
58
'Maximum on scale: ' +
59
settings.maximum +
60
' %'
61
);
62
63
return gauge;
64
}
65
66
// Create gauges
67
var world = drawGauge(13.68, { maximum: 50, value: 27.13 });
68
var europe = drawGauge(36.98, { maximum: 50, value: 47.28 });
69
var nAmerica = drawGauge(36.77, { maximum: 50, value: 46.53 });
70
var sAmerica = drawGauge(22.8, { maximum: 50, value: 40.54 });
71
var asia = drawGauge(10.14, { maximum: 50, value: 27.16 });
72
var oceania = drawGauge(9.75, { maximum: 50, value: 22.12 });
73
var africa = drawGauge(1.56, { maximum: 50, value: 3.04 });
74
75
world.a11y(true);
76
europe.a11y(true);
77
nAmerica.a11y(true);
78
79
// Create standalone legend
80
var legend = anychart.standalones.legend();
81
legend
82
.position('center')
83
//.fontSize(14)
84
.items([
85
{ text: 'Fully vaccinated', iconFill: '#296953' },
86
{ text: 'Partially vaccinated', iconFill: '#63b39b' },
87
{ text: 'Not vaccinated', iconFill: '#eee' }
88
]);
89
90
// Create table to place gauges
91
var layoutTable = anychart.standalones.table();
92
layoutTable
93
.hAlign('right')
94
.vAlign('middle')
95
.fontSize(14)
96
.cellBorder(null);
97
98
// Put gauges into the layout table
99
layoutTable.contents([
100
[null, 'COVID19 Vaccination - How far are we from the halfway mark?'],
101
[null, '% of population partially and fully vaccinated'],
102
[null, legend],
103
['World', world],
104
['Europe', europe],
105
['North America', nAmerica],
106
['South America', sAmerica],
107
['Asia', asia],
108
['Oceania', oceania],
109
['Africa', africa]
110
]);
111
112
// Set height for first row in layout table
113
layoutTable
114
.getRow(0)
115
.height(30)
116
.fontSize(20)
117
.hAlign('center');
118
119
layoutTable
120
.getRow(1)
121
.height(40)
122
.fontSize(16)
123
.hAlign('center');
124
125
layoutTable.getRow(2).height(40).fontSize(12);
126
layoutTable.getCol(0).width(100);
127
128
// Set container id and initiate drawing
129
layoutTable.container('container');
130
layoutTable.draw();
131
});