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