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
// Set gauge type
3
var gauge = anychart.gauges.linear();
4
// The data used in this sample can be obtained from the CDN
5
// https://cdn.anychart.com/samples/linear-gauges/tallest-building/data.js
6
var data = getData(); // eslint-disable-line no-undef
7
8
// Set credits
9
gauge
10
.credits()
11
.enabled(true)
12
.url(
13
'https://en.wikipedia.org/wiki/List_of_tallest_buildings_and_structures'
14
)
15
.text(
16
'Data source: https://en.wikipedia.org/wiki/List_of_tallest_buildings_and_structures'
17
)
18
.logoSrc('https://en.wikipedia.org/static/favicon/wikipedia.ico');
19
20
// Creates data set on our data
21
gauge.data(data);
22
gauge.padding([0, 0, 50, 0]);
23
24
// Set Chart Title
25
var title = gauge.title();
26
title
27
.enabled(true)
28
.useHtml(true)
29
.padding([10, 0, 15, 0])
30
.text(
31
'Tallest Building by Function<br>' +
32
'<span style="color: #212121; font-size: 12px">(According to Wikipedia.org)</span>'
33
);
34
35
// Helper function to create Bar Series
36
function createBar(i, color) {
37
// Create bar pointer
38
var bar = gauge.bar(i);
39
bar
40
.color(color)
41
// Set pointer offset of the width gauge
42
.offset(i * 13 - 10)
43
// Set pointer width
44
.width('9%')
45
.name(
46
data[i].name +
47
'<br/><span style="color: #212121; font-size: 10px">' +
48
data[i].country +
49
',<br/>' +
50
data[i].city +
51
'</span>'
52
);
53
54
// Set pointer label
55
bar
56
.labels()
57
.enabled(true)
58
.position('center')
59
.anchor('center')
60
.rotation(-90)
61
.fontSize(11)
62
.fontColor('white')
63
.format(function () {
64
return this.getData('category');
65
});
66
bar
67
.hovered()
68
.labels()
69
.enabled(true)
70
.fontColor('#212121')
71
.fontWeight('600');
72
bar
73
.selected()
74
.labels()
75
.enabled(true)
76
.fontColor('white')
77
.fontWeight('600');
78
79
// Set marker pointer
80
var marker = gauge.marker(i);
81
marker.color(color).offset('-14%');
82
marker
83
.labels()
84
.enabled(true)
85
.position('left-center')
86
.offsetX(-5)
87
.anchor('right-center')
88
.format('{%Value} m.');
89
marker
90
.hovered()
91
.labels()
92
.enabled(true)
93
.fontColor('#212121')
94
.fontWeight('600');
95
marker
96
.selected()
97
.labels()
98
.enabled(true)
99
.fontColor('#212121')
100
.fontWeight('600');
101
marker.legendItem(false);
102
marker.type('arrowhead');
103
}
104
105
// Create series
106
createBar(0, '#024174');
107
createBar(1, '#02579A');
108
createBar(2, '#1976D3');
109
createBar(3, '#42A5F6');
110
createBar(4, '#90CAF8');
111
createBar(5, '#b3e5fc');
112
113
var legend = gauge.legend();
114
// Turn on legend and sets settings
115
legend
116
.enabled(true)
117
.useHtml(true)
118
.padding([0, 30, 0, 30])
119
.fontSize(12)
120
.position('left')
121
.align('top')
122
.itemsLayout('vertical');
123
124
// Set paginator in the bottom position
125
legend.paginator().orientation('bottom');
126
127
// remove all listeners for legend
128
legend.removeAllListeners();
129
130
// Set axis scale settings
131
var scale = gauge.scale();
132
scale.ticks([0, 1000]);
133
134
// Enable axis
135
var axis = gauge.axis();
136
axis.offset('-11%').width('0%');
137
// Set axis labels formatter
138
axis.labels().useHtml(true).format('{%Value} m.');
139
140
// Set tooltip formatter
141
gauge
142
.tooltip()
143
.useHtml(true)
144
.format(function () {
145
return (
146
'<span style="color: #EAEAEA;">' +
147
this.getData('country') +
148
', ' +
149
this.getData('city') +
150
'<br/><span style="font-size: 14px">' +
151
this.value +
152
' m.</span></span>'
153
);
154
});
155
gauge.tooltip().titleFormat(function () {
156
return this.getData('name');
157
});
158
gauge.tooltip().titleFormat(function () {
159
return this.getData('name');
160
});
161
162
// Set container id and initiate drawing
163
gauge.container('container');
164
gauge.draw();
165
});