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
var labelDate;
2
3
var colorAxisFont = '#7c868e';
4
var darkAccentColor = '#545f69';
5
var darkAxisColor = '#B9B9B9';
6
7
anychart.onDocumentReady(function () {
8
var gauge = anychart.gauges.circular();
9
gauge.title('Analog Watch\nwith Anychart');
10
gauge.title().fontSize(20).hAlign('center').padding(0, 0, 20, 0);
11
gauge
12
.fill('#ffffff')
13
.stroke('2 #B9B9B9')
14
.padding(0)
15
.margin(30)
16
.startAngle(0)
17
.sweepAngle(360);
18
19
labelDate = gauge.label();
20
labelDate
21
.text(2)
22
.fontColor('#64B5F6')
23
.anchor('center')
24
.zIndex(10)
25
.offsetY('64%')
26
.offsetX(90)
27
.padding(3, 5)
28
.width('12%')
29
.height('7%')
30
.hAlign('right')
31
.adjustFontSize(true)
32
.zIndex(10)
33
.background({
34
fill: '#fff',
35
stroke: { thickness: 1, color: '#E0F0FD' }
36
});
37
38
var nameLabel = gauge.label(1);
39
nameLabel
40
.text(
41
'<span style="color: #D0E9FC">AnyChart</span><br>' +
42
'<span style="color: #E0F0FD">TIME</span>'
43
)
44
.useHtml(true)
45
.width('40%')
46
.height('12%')
47
.hAlign('center')
48
.anchor('center-bottom')
49
.adjustFontSize(true)
50
.zIndex(10)
51
.offsetY('15%');
52
53
function getTime() {
54
var now = new Date();
55
var seconds = now.getSeconds() + now.getMilliseconds() / 1000;
56
var minutes = now.getMinutes() + seconds / 60;
57
var hours = (now.getHours() % 12) + minutes / 60;
58
labelDate.text(now.getUTCDate() + '/' + (now.getUTCMonth() + 1));
59
return [Math.floor(hours), Math.floor(minutes), Math.floor(seconds)];
60
}
61
62
gauge.data(getTime());
63
setInterval(function () {
64
gauge.data(getTime());
65
}, 1000);
66
67
var hoursAxis = gauge.axis();
68
hoursAxis.fill(null).radius(103).width(1);
69
hoursAxis
70
.labels()
71
.fontSize(20)
72
.padding(5)
73
.position('inside')
74
.anchor('center')
75
.format(function () {
76
if (this.value === 0) return 'XII';
77
if (this.value === 1) return 'I';
78
if (this.value === 2) return 'II';
79
if (this.value === 3) return 'III';
80
if (this.value === 4) return 'IIV';
81
if (this.value === 5) return 'V';
82
if (this.value === 6) return 'VI';
83
if (this.value === 7) return 'VII';
84
if (this.value === 8) return 'VIII';
85
if (this.value === 9) return 'IX';
86
if (this.value === 10) return 'X';
87
if (this.value === 11) return 'XI';
88
return this.value;
89
});
90
hoursAxis
91
.scale()
92
.minimum(0)
93
.maximum(12)
94
.ticks({ interval: 1 })
95
.minorTicks({ interval: 1 });
96
hoursAxis.ticks().enabled(false);
97
hoursAxis.minorTicks().enabled(false);
98
99
var minuteAxis = gauge.axis(1);
100
minuteAxis.radius(107).fill(null).width(3).fill('#F0F8FE');
101
minuteAxis.labels().enabled(false);
102
minuteAxis
103
.scale()
104
.minimum(0)
105
.maximum(60)
106
.ticks({ interval: 5 })
107
.minorTicks({ interval: 1 });
108
109
minuteAxis
110
.ticks()
111
.enabled(true)
112
.length(10)
113
.stroke('2 ' + darkAccentColor)
114
.position('center')
115
.type(function (path, x, y, radius) {
116
path
117
.moveTo(x, y - radius / 2)
118
.lineTo(x, y + radius / 2)
119
.close();
120
return path;
121
});
122
123
minuteAxis
124
.minorTicks()
125
.enabled(true)
126
.length(5)
127
.stroke('1.4 ' + colorAxisFont)
128
.position('center')
129
.type(function (path, x, y, radius) {
130
path
131
.moveTo(x, y - radius / 2)
132
.lineTo(x, y + radius / 2)
133
.close();
134
return path;
135
});
136
137
gauge
138
.needle()
139
.fill(darkAccentColor)
140
.stroke(null)
141
.startRadius('6%')
142
.endRadius('55%')
143
.startWidth('2%')
144
.middleWidth('2%')
145
.endWidth('2%');
146
gauge
147
.needle(1)
148
.fill(darkAccentColor)
149
.stroke(null)
150
.axisIndex(1)
151
.startRadius('6%')
152
.endRadius('80%')
153
.startWidth('1%')
154
.middleWidth('1%')
155
.endWidth('1%');
156
gauge
157
.needle(2)
158
.fill(darkAxisColor)
159
.stroke(null)
160
.startRadius('6%')
161
.endRadius('85%')
162
.startWidth('0.5%')
163
.middleWidth('0.5%')
164
.axisIndex(1)
165
.endWidth('0.5%');
166
gauge
167
.cap()
168
.radius('5%')
169
.enabled(true)
170
.fill(darkAccentColor)
171
.stroke(null);
172
173
gauge.container('container');
174
gauge.draw();
175
});