HTMLcopy
1
<div id="container"></div>
CSScopy
6
1
html, body, #container {
2
width: 100%;
3
height: 100%;
4
margin: 0;
5
padding: 0;
6
}
JavaScriptcopy
x
1
anychart.onDocumentReady(function () {
2
// set theme
3
anychart.theme({
4
linearGauge: {
5
defaultPointerSettings: {
6
led: {
7
// darken the color value
8
// exceeds the value of Pointer
9
dimmer: function () {
10
return '#e65100';
11
},
12
// pointer width as a percentage
13
// of the width gauge
14
width: '15%',
15
// set color pointer led
16
colorScale: {
17
type: 'linear-color',
18
colors: '#57a7b1'
19
},
20
// the distance between the "tiles"
21
// pointer to a percentage of the pointer height
22
gap: '.5%',
23
// set size "tiles" null
24
size: null
25
},
26
bar: {
27
// enable hover labels
28
hoverLabel: {
29
enabled: true,
30
fontColor: anychart.color.lighten('#455a64', 0.1)
31
},
32
// enable select labels
33
selectLabel: {
34
enabled: true,
35
fontColor: anychart.color.darken('#455a64', 0.5)
36
},
37
color: '#455a64',
38
// pointer width as a percentage
39
// of the width gauge
40
width: '1%',
41
// set label settings
42
label: {
43
enabled: true,
44
fontSize: '21px',
45
fontColor: '#455a64',
46
position: 'center',
47
offsetY: '-4%'
48
}
49
}
50
},
51
defaultAxisSettings: {
52
// set axis width
53
width: '1%',
54
// set label settings
55
labels: {
56
fontColor: '#96a6a6',
57
fontSize: '21px',
58
fontWeight: 700
59
},
60
// set for axis orientation
61
orientation: 'bottom'
62
}
63
}
64
});
65
66
// create data
67
var data = [17.15, 14.55, 11.53, 5.35];
68
69
// gauge type
70
var gauge = anychart.gauges.linear();
71
// create data set on our data
72
gauge.data(data);
73
// set global offset
74
gauge.globalOffset('-5%');
75
// set gauge padding
76
gauge.padding([15, 20, 10, 20]);
77
// set container id for the gauge
78
gauge.container('container');
79
// set position gauge
80
gauge.layout('horizontal');
81
82
// create scale (0-30)
83
var scaleFirst = anychart.scales.linear();
84
// set scale minimum
85
scaleFirst.minimum(0);
86
// set scale maximum
87
scaleFirst.maximum(30);
88
// set interval major axis ticks
89
scaleFirst.ticks().interval(5);
90
91
// create scale (0-24)
92
var scaleSecond = anychart.scales.linear();
93
// set scale minimum
94
scaleSecond.minimum(0);
95
// set scale maximum
96
scaleSecond.maximum(24);
97
// set interval major axis ticks
98
scaleSecond.ticks().interval(3);
99
100
// create led pointer of the data index zero
101
var ledPointerFirst = gauge.led(0);
102
// pointer offset as a percentage of the width gauge
103
ledPointerFirst.offset('-20%');
104
// set pointer name
105
ledPointerFirst.name('LED Pointer First');
106
// count "tiles"
107
ledPointerFirst.count('6');
108
// set scale
109
ledPointerFirst.scale(scaleFirst);
110
111
// create led pointer of the data index one
112
var ledPointerSecond = gauge.led(1);
113
// pointer offset as a percentage of the width gauge
114
ledPointerSecond.offset('45%');
115
// set pointer name
116
ledPointerSecond.name('LED Pointer Second');
117
// count "tiles"
118
ledPointerSecond.count('8');
119
// set scale
120
ledPointerSecond.scale(scaleSecond);
121
122
// create bar pointer of the data index two
123
var barFirst = gauge.bar(2);
124
// set pointer name
125
barFirst.name('Bar Pointer First');
126
// pointer offset as a percentage of the width gauge
127
barFirst.offset('-23%');
128
// set scale
129
barFirst.scale(scaleFirst);
130
131
// create bar pointer of the data index three
132
var barSecond = gauge.bar(3);
133
// set pointer name
134
barSecond.name('Bar Pointer Second');
135
// pointer offset as a percentage of the width gauge
136
barSecond.offset('42%');
137
// set scale
138
barSecond.scale(scaleSecond);
139
140
var labelBarFirst = barFirst.labels();
141
// labels format, set current value gauge
142
labelBarFirst.format(function () {
143
return gauge.data().get(2, 'value');
144
});
145
146
var labelBarSecond = barSecond.labels();
147
// labels format, set current value gauge
148
labelBarSecond.format(function () {
149
return gauge.data().get(3, 'value');
150
});
151
152
var axisFirst = gauge.axis(0);
153
// axis offset as a percentage of the width gauge
154
axisFirst.offset('-3%');
155
// set axis scale
156
axisFirst.scale(scaleFirst);
157
158
var axisSecond = gauge.axis(1);
159
// axis offset as a percentage of the width gauge
160
axisSecond.offset('62%');
161
// set axis scale
162
axisSecond.scale(scaleSecond);
163
164
// initiate gauge drawing
165
gauge.draw();
166
167
});