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
$('#container').append(
3
'<div class="control-container"><span class="edge left">0</span>' +
4
'<input id="rangeInput" name="rangeInput" type="range" min="0" max="200" step="1" value="65">' +
5
'<span class="edge right">200</span></div>'
6
);
7
8
// Create data for this sample
9
var data = [65, 65, 65, 65, 65];
10
11
// Create gauge
12
var gauge = anychart.gauges.linear();
13
gauge.data(data);
14
gauge.padding([30, 0, 80, 0]);
15
gauge.tooltip().format(function () {
16
var value = this.value;
17
var index = this.index;
18
19
return 'Value: ' + formatText(index, value);
20
});
21
22
// Set gauge title
23
gauge
24
.title()
25
.enabled(true)
26
.padding([0, 0, 35, 0])
27
.text('Multiple LED Pointers with Different Scales');
28
29
function createGaugeSeries(min, max, name, offset, i) {
30
// Create scale
31
var scale = anychart.scales.linear();
32
scale.minimum(min).maximum(max);
33
34
// Create led pointer
35
var ledSeries = gauge.led(i);
36
ledSeries
37
.name(name)
38
.size('1%')
39
.gap('1.25%')
40
.width('9%')
41
.offset(offset)
42
.scale(scale)
43
.dimmer(function () {
44
return '#EAEAEA';
45
});
46
47
// Create led label
48
ledSeries
49
.labels()
50
.enabled(true)
51
.offsetY('-15px')
52
.format(function () {
53
var value = this.value;
54
var index = this.index;
55
56
return formatText(index, value);
57
});
58
ledSeries
59
.hovered()
60
.labels()
61
.enabled(true)
62
.fontColor('#545f69')
63
.fontWeight('600');
64
ledSeries
65
.selected()
66
.labels()
67
.enabled(true)
68
.fontColor('#545f69')
69
.fontWeight('600');
70
71
// Create custom color scale for pointer
72
ledSeries.colorScale(
73
anychart.scales.ordinalColor().ranges([
74
{
75
from: min,
76
to: (max - min) / 2,
77
color: '#64b5f6'
78
},
79
{
80
from: (max - min) / 2,
81
to: max,
82
color: '#F7F7F7'
83
}
84
])
85
);
86
}
87
88
createGaugeSeries(0, 100, 'First', 0, 0);
89
createGaugeSeries(35, 200, 'Second', 10, 1);
90
createGaugeSeries(15, 150, 'Third', 20, 2);
91
createGaugeSeries(10, 175, 'Forth', 30, 3);
92
createGaugeSeries(5, 120, 'Fifth', 40, 4);
93
94
// Initiate gauge drawing
95
gauge.container('container');
96
97
gauge.draw();
98
99
// set data of the led pointer's from range input
100
$('#rangeInput').on('change', function () {
101
gauge.data().set(0, 'value', $(this).val());
102
gauge.data().set(1, 'value', $(this).val());
103
gauge.data().set(2, 'value', $(this).val());
104
gauge.data().set(3, 'value', $(this).val());
105
gauge.data().set(4, 'value', $(this).val());
106
});
107
108
function formatText(index, value) {
109
switch (index) {
110
case 0:
111
return value >= 100 ? 100 : value;
112
case 1:
113
return value >= 200 ? 200 : value;
114
case 2:
115
return value >= 150 ? 150 : value;
116
case 3:
117
return value >= 175 ? 175 : value;
118
case 4:
119
return value >= 120 ? 120 : value;
120
default:
121
}
122
}
123
});