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 = [25];
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: 25,
21
color: ['#dd2c00']
22
},
23
{
24
from: 25,
25
to: 50,
26
color: ['#ef6c00']
27
},
28
{
29
from: 50,
30
to: 75,
31
color: ['#16685d']
32
},
33
{
34
from: 75,
35
to: 100 ,
36
color: ['#00838f']
37
}
38
]
39
);
40
41
// create a Scale Bar
42
var scaleBar = gauge.scaleBar(0);
43
44
// set the relative height of the control points of the scale bar
45
scaleBar.points([
46
{height: 1, left: 1, right: 0}
47
]);
48
49
// set the height and offset of the Scale Bar (both as percentages of the gauge height)
50
scaleBar.width('10%');
51
scaleBar.offset('31%');
52
53
// use the color scale (defined earlier) as the color scale of the Scale Bar
54
scaleBar.colorScale(scaleBarColorScale);
55
56
// add a marker pointer
57
var marker = gauge.marker(0);
58
59
// set the color of the marker
60
marker.color('black');
61
62
// set the width of the marker
63
marker.width(15);
64
65
// set the offset of the pointer as a percentage of the gauge width
66
marker.offset('43%');
67
68
// set the marker type
69
marker.type('triangle-up');
70
71
// set the zIndex of the marker
72
marker.zIndex(10);
73
74
// configure the scale
75
var scale = gauge.scale();
76
scale.minimum(0);
77
scale.maximum(100);
78
scale.ticks().interval(10);
79
80
// configure the axis
81
var axis = gauge.axis();
82
axis.minorTicks(true)
83
axis.minorTicks().stroke('#cecece');
84
axis.width('1%');
85
axis.offset('29.5%');
86
axis.orientation('top');
87
88
// format axis labels
89
axis.labels().format('{%value}%');
90
91
// set paddings
92
gauge.padding([0, 50]);
93
94
// set the container id
95
gauge.container('container');
96
97
// initiate drawing the gauge
98
gauge.draw();
99
});