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 data
3
var data = [1000, 920, 800, 640];
4
5
// Set gauge type
6
var gauge = anychart.gauges.linear();
7
8
// Creates data set on our data
9
gauge.data(data);
10
11
// Set Chart Title
12
gauge
13
.title()
14
.enabled(true)
15
.useHtml(true)
16
.padding([0, 0, 15, 0])
17
.text(
18
'Weight and Volume Ratio of Product<br>' +
19
'<span style="color: #212121; font-size: 12px">The amount in one kilogram </span>'
20
);
21
22
// Helper function to create Tank Series
23
function createTank(i, name, offset, color) {
24
// Create tank pointer of the data index
25
gauge
26
.tank(i)
27
// Set pointer name
28
.name(name)
29
// Set pointer color fill
30
.color(color)
31
// Set pointer offset of the width gauge
32
.offset(offset)
33
// Set pointer width
34
.width('10%');
35
}
36
37
// Create series
38
createTank(0, 'Water', '0%', '#64b5f6');
39
createTank(1, 'Olive oil', '11%', '#ffee58');
40
createTank(2, 'Sugar', '22%', '#ffe0b2');
41
createTank(3, 'Ground coffee', '33%', '#4e342e');
42
43
// Turn on legend and sets some padding
44
gauge.legend().enabled(true).padding([0, 0, 30, 0]);
45
46
// Set axis scale settings
47
var scale = gauge.scale();
48
scale
49
.minimum(0)
50
.maximum(1000)
51
// Set axis tick intervals
52
.ticks({ interval: 200 })
53
.minorTicks({ interval: 100 });
54
55
// Enable axis minor ticks and sets axis offset
56
var axis = gauge.axis();
57
axis.minorTicks(true).width('0').offset('-1%');
58
59
// Set axis labels formatter
60
axis.labels().useHtml(true).format('{%Value} ml.');
61
62
// Set tooltip formatter
63
gauge.tooltip().format('{%Value} ml.');
64
65
// Set container id and initiate drawing
66
gauge.container('container');
67
gauge.draw();
68
});