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
3
// create data
4
var data = [63];
5
6
// set the gauge type
7
var gauge = anychart.gauges.linear();
8
9
// set the data for the gauge
10
gauge.data(data);
11
12
// set the layout
13
gauge.layout('horizontal');
14
15
// create a color scale
16
var scaleBarColorScale = anychart.scales.ordinalColor().ranges(
17
[
18
{
19
from: 0,
20
to: 0.25,
21
color: ['#D81E05', '#EB7A02']
22
},
23
{
24
from: 0.25,
25
to: 0.5,
26
color: ['#EB7A02', '#FFD700']
27
},
28
{
29
from: 0.5,
30
to: 0.75,
31
color: ['#FFD700', '#CAD70b']
32
},
33
{
34
from: 0.75,
35
to: 1,
36
color: ['#CAD70b', '#2AD62A']
37
}
38
]
39
);
40
41
// create a Scale Bar
42
var scaleBar = gauge.scaleBar(0);
43
44
// set the height and offset of the Scale Bar (both as percentages of the gauge height)
45
scaleBar.width('5%');
46
scaleBar.offset('31.5%');
47
48
// use the color scale (defined earlier) as the color scale of the Scale Bar
49
scaleBar.colorScale(scaleBarColorScale);
50
51
// add a marker pointer
52
var marker = gauge.marker(0);
53
54
// set the offset of the pointer as a percentage of the gauge width
55
marker.offset('31.5%');
56
57
// set the marker type
58
marker.type('triangleUp');
59
60
// set the zIndex of the marker
61
marker.zIndex(10);
62
63
// configure the scale
64
var scale = gauge.scale();
65
scale.minimum(0);
66
scale.maximum(100);
67
scale.ticks().interval(10);
68
69
// configure the axis
70
var axis = gauge.axis();
71
axis.minorTicks(true)
72
axis.minorTicks().stroke('#cecece');
73
axis.width('1%');
74
axis.offset('29.5%');
75
axis.orientation('top');
76
77
// format axis labels
78
axis.labels().format('{%Value}%');
79
80
// set paddings
81
gauge.padding([0, 50]);
82
83
// set the container id
84
gauge.container('container');
85
86
// initiate drawing the gauge
87
gauge.draw();
88
});