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 table to place gauges and information
3
var layoutTable = anychart.standalones.table(4, 3);
4
layoutTable
5
.hAlign('center')
6
.vAlign('middle')
7
.useHtml(true)
8
.fontSize(16)
9
.cellBorder(null);
10
11
// Set height and width for some cols and rows for layout table
12
layoutTable.getCol(2).width('50%');
13
layoutTable.getRow(0).height(60).fontSize(18);
14
layoutTable.getRow(1).height(60);
15
layoutTable.getRow(3).height(60).fontSize(14).vAlign('top');
16
17
// Merge cells in layout table where needed
18
layoutTable.getCell(0, 0).colSpan(3);
19
layoutTable
20
.getCell(1, 0)
21
.colSpan(2)
22
.fontColor('#212121')
23
.fontWeight(600);
24
25
// Put data and charts into the layout table
26
layoutTable.contents([
27
[
28
'The Weather in the Resort<br/><span style="color:#1976d2; font-size: 16px; font-weight: 300">' +
29
anychart.format.dateTime(new Date(), 'dd MMMM yyyy') +
30
'</span>',
31
null,
32
null
33
],
34
[
35
'Cloudy, no precipitation',
36
null,
37
'Humidity <span style="color:#212121; font-size: 24px; font-weight: 600">73%</span>'
38
],
39
[drawLinearGauge(28), drawLinearGauge(22), drawCircularGauge(305, 6)],
40
[
41
'Temperature<br/>of the air',
42
'Temperature<br/>of the sea',
43
'Wind direction<br/>and strength'
44
]
45
]);
46
47
// Set container id and initiate drawing
48
layoutTable.container('container');
49
layoutTable.draw();
50
51
// Helper function to create linear gauge
52
function drawLinearGauge(value) {
53
var gauge = anychart.gauges.linear();
54
gauge.data([value]);
55
gauge.tooltip(false);
56
57
// Create thermometer title
58
gauge
59
.title()
60
.enabled(true)
61
.text(value + '°')
62
.fontColor('#212121')
63
.fontWeight(600)
64
.fontSize(24)
65
.orientation('bottom')
66
.useHtml(true)
67
.padding([10, 0, 5, 0]);
68
69
// Create thermometer pointer
70
var thermometer = gauge.thermometer(0);
71
72
// Set thermometer settings
73
thermometer.offset('1').width('3%').fill('#64b5f6').stroke('#64b5f6');
74
75
// Set scale settings
76
var scale = gauge.scale();
77
scale
78
.minimum(0)
79
.maximum(40)
80
.ticks({ interval: 10 })
81
.minorTicks({ interval: 1 });
82
// Set axis and axis settings
83
var axis = gauge.axis();
84
axis.scale(scale).minorTicks(true).width('0').offset('0%');
85
86
// Set text formatter for axis labels
87
axis.labels().useHtml(true).format('{%Value}°');
88
89
return gauge;
90
}
91
92
// Helper function to create circular gauge
93
function drawCircularGauge(direction, force) {
94
var gauge = anychart.gauges.circular();
95
gauge.fill('white').margin(30).stroke(null).tooltip(false);
96
gauge.data([direction]);
97
98
gauge
99
.axis()
100
.scale()
101
.minimum(0)
102
.maximum(360)
103
.ticks({ interval: 45 })
104
.minorTicks({ interval: 45 });
105
gauge
106
.axis()
107
.startAngle(0)
108
.fill('#CECECE')
109
.width(2)
110
.radius(100)
111
.sweepAngle(360);
112
gauge
113
.axis()
114
.ticks()
115
.enabled(true)
116
.length(20)
117
.stroke('2 #CECECE')
118
.position('inside')
119
.type(function (path, x, y, radius) {
120
path
121
.moveTo(x, y - radius / 2)
122
.lineTo(x, y + radius / 2)
123
.close();
124
return path;
125
});
126
127
gauge
128
.axis()
129
.labels()
130
.fontSize(20)
131
.position('outside')
132
.format(function () {
133
if (this.value === 0) return 'N';
134
if (this.value === 45) return 'ne';
135
if (this.value === 90) return 'E';
136
if (this.value === 135) return 'se';
137
if (this.value === 180) return 'S';
138
if (this.value === 225) return 'sw';
139
if (this.value === 270) return 'W';
140
if (this.value === 315) return 'nw';
141
return this.value;
142
});
143
144
gauge
145
.needle()
146
.fill('#64b5f6')
147
.stroke('#64b5f6')
148
.startRadius('45%')
149
.middleRadius('5%')
150
.endRadius('-85%')
151
.startWidth('0%')
152
.endWidth('0%')
153
.middleWidth('20%');
154
155
gauge
156
.cap()
157
.radius('30%')
158
.enabled(true)
159
.fill('#fff')
160
.stroke('#CECECE');
161
162
gauge
163
.label()
164
.hAlign('center')
165
.anchor('center')
166
.text(
167
'<span style="color: #212121; font-weight: 600">' +
168
direction +
169
'</span>\u00B0<br>' +
170
'<span style="color: #212121; font-weight: 600">' +
171
force +
172
'</span> m/s'
173
)
174
.useHtml(true);
175
176
return gauge;
177
}
178
});