-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathchart.html
More file actions
358 lines (309 loc) · 13.1 KB
/
chart.html
File metadata and controls
358 lines (309 loc) · 13.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
<!--前排提醒!!!如果你是用Edge浏览器打开本前端网页,一定要把自动翻译成中文这个选项关掉,本人骆灿坤亲测如果你打开了自动翻译edge的史山优化会自动更改你的前端字符!!!此事不仅我这里发生,在github亦有记载-->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>哈威SSR团队作品前端展示</title>
<!-- 引入SB Admin 2的CSS -->
<link href="css/sb-admin-2.min.css" rel="stylesheet">
<!-- 引入Font Awesome图标库 -->
<link href="vendor/fontawesome-free/css/all.min.css" rel="stylesheet" type="text/css">
<!-- 引入Toastr CSS(用于通知弹窗) -->
<link href="vendor/toastr/toastr.min.css" rel="stylesheet">
<!-- 引入Chart.js -->
<script src="https://cdn.jsdelivr.net/npm/chart.js@3.9.1/dist/chart.min.js"></script>
<!-- 引入Toastr JS -->
<script src="vendor/toastr/toastr.min.js"></script>
<!-- 添加自定义CSS -->
<style>
/* 自定义图表容器样式 */
.chart-container {
width: 100%;
margin-bottom: 50px;
width: 500px;
height: 444px;
}
/* 使用Bootstrap的网格系统,将图表排列为一行两列 */
.row-cols-1.row-cols-md-2 {
display: flex;
flex-wrap: wrap;
}
.col-md-6 {
flex: 0 0 50%;
max-width: 50%;
padding: 10px;
}
/* 调整canvas大小以适应卡片 */
canvas {
max-width: 100%;
height: 300px;
/* 固定高度以确保一致性 */
}
.m-gamepadItemJoysticks {
background: none;
padding: 20px;
margin-left: 333px;
}
button {
padding: 10px;
margin: 5px;
cursor: pointer;
}
</style>
</head>
<body id="page-top">
<!-- Page Wrapper -->
<div id="wrapper">
<!-- Sidebar -->
<ul class="navbar-nav bg-gradient-primary sidebar sidebar-dark accordion" id="accordionSidebar">
<!-- Sidebar Brand -->
<a class="sidebar-brand d-flex align-items-center justify-content-center" href="first_page.html">
<div class="sidebar-brand-icon rotate-n-15">
<i class="fas fa-laugh-wink"></i>
</div>
<div class="sidebar-brand-text mx-3">
<font _mstmutation="1" _msttexthash="10666266" _msthash="1">SSR团队</font>
</div>
</a>
<!-- Divider -->
<hr class="sidebar-divider my-0">
<!-- Nav Item - Dashboard -->
<li class="nav-item">
<a class="nav-link" href="first_page.html">
<i class="fas fa-fw fa-tachometer-alt"></i>
<span _msttexthash="8308430" _msthash="3">首页展示</span></a>
</li>
<hr class="sidebar-divider">
<div class="sidebar-heading" _msttexthash="4554719" _msthash="4">数据图表</div>
<li class="nav-item active">
<a class="nav-link" href="text.html">
<i class="fas fa-fw fa-chart-area"></i>
<span _msttexthash="5658250" _msthash="24">图表</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="tables.html">
<i class="fas fa-fw fa-table"></i>
<span _msttexthash="3177720" _msthash="25">表格</span></a>
</li>
<!-- 你可以添加更多导航项 -->
<li class="nav-item">
<a class="nav-link collapsed" href="XBox.html">
<i class="fas fa-fw fa-cog"></i>
<span _msttexthash="5055388" _msthash="5">手柄效果</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link collapsed" href="camera.html">
<i class="fas fa-fw fa-camera"></i>
<span _msttexthash="5055388" _msthash="5">摄像头读取</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="http://localhost:8001/vendor/three.js-r161/examples/sinmple.html">
<i class="fas fa-fw fa-wrench"></i>
<span>模型展示</span>
</a>
</li>
</ul>
<!-- End of Sidebar -->
<!-- Content Wrapper -->
<div id="content-wrapper" class="d-flex flex-column">
<!-- Main Content -->
<div id="content">
<!-- Topbar -->
<nav class="navbar navbar-expand navbar-light bg-white topbar mb-4 static-top shadow">
<!-- Sidebar Toggle (Topbar) -->
<button id="sidebarToggleTop" class="btn btn-link d-md-none rounded-circle mr-3">
<i class="fa fa-bars"></i>
</button>
<!-- Topbar Navbar -->
<ul class="navbar-nav ml-auto">
<!-- 可添加更多内容 -->
<li class="nav-item dropdown no-arrow">
<a class="nav-link dropdown-toggle" href="#" id="userDropdown" role="button"
data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<span class="mr-2 d-none d-lg-inline text-gray-600 small" _msttexthash="22648327"
_msthash="55">SSR团队研发</span>
<img class="img-profile rounded-circle" src="img/picture.png">
</a>
</li>
</ul>
</nav>
<!-- End of Topbar -->
<!-- Begin Page Content -->
<div class="container-fluid">
<!-- Page Heading -->
<div class="d-sm-flex align-items-center justify-content-between mb-4">
<h1 class="h3 mb-0 text-gray-800">各项数值展示</h1>
</div>
<!-- Content Row -->
<div class="row">
<!-- Area Chart -->
<div class="col-xl-8 col-lg-7">
<div class="card shadow mb-4">
<!-- Card Header - Dropdown -->
<div
class="card-header py-3 d-flex flex-row align-items-center justify-content-between">
<h6 class="m-0 font-weight-bold text-primary">Earnings Overview</h6>
<div class="dropdown no-arrow">
<a class="dropdown-toggle" href="#" role="button" id="dropdownMenuLink"
data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<i class="fas fa-ellipsis-v fa-sm fa-fw text-gray-400"></i>
</a>
<div class="dropdown-menu dropdown-menu-right shadow animated--fade-in"
aria-labelledby="dropdownMenuLink">
<div class="dropdown-header">Dropdown Header:</div>
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="#">Something else here</a>
</div>
</div>
</div>
<!-- Card Body -->
<div class="card-body">
<div class="chart-area">
<canvas id="myAreaChart"></canvas>
</div>
</div>
</div>
</div>
</div>
<!-- Content Row -->
</div>
<!-- /.container-fluid -->
</div>
<!-- End of Main Content -->
<!-- Footer -->
<footer class="sticky-footer bg-white">
<div class="container my-auto">
<div class="copyright text-center my-auto">
<span>Copyright © Your Website 2021</span>
</div>
</div>
</footer>
<!-- End of Footer -->
</div>
<!-- End of Content Wrapper -->
</div>
<!-- End of Page Wrapper -->
<!-- Scroll to Top Button-->
<a class="scroll-to-top rounded" href="#page-top">
<i class="fas fa-angle-up"></i>
</a>
<!-- Logout Modal-->
<div class="modal fade" id="logoutModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel"
aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Ready to Leave?</h5>
<button class="close" type="but ton" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">Select "Logout" below if you are ready to end your current session.</div>
<div class="modal-footer">
<button class="btn btn-secondary" type="button" data-dismiss="modal">Cancel</button>
<a class="btn btn-primary" href="login.html">Logout</a>
</div>
</div>
</div>
</div>
<!-- Bootstrap core JavaScript-->
<script src="vendor/jquery/jquery.min.js"></script>
<script src="vendor/bootstrap/js/bootstrap.bundle.min.js"></script>
<!-- Core plugin JavaScript-->
<script src="vendor/jquery-easing/jquery.easing.min.js"></script>
<!-- Custom scripts for all pages-->
<script src="js/sb-admin-2.min.js"></script>
<!-- Page level plugins -->
<script src="vendor/chart.js/Chart.min.js"></script>
<!-- Page level custom scripts -->
<script src="js/demo/chart-area-demo.js"></script>
<script src="js/demo/chart-pie-demo.js"></script>
</body>
<script>
// 全局时间步,用于计算周期
let timeStep = 0;
// 初始温度:25~30℃随机
let currentTemp = 25 + Math.random() * 5;
// 生成高斯随机数(Box–Muller 方法)
function gaussianRand() {
let u = 0, v = 0;
while (u === 0) u = Math.random();
while (v === 0) v = Math.random();
return Math.sqrt(-2 * Math.log(u)) * Math.cos(2 * Math.PI * v);
}
// 根据上一温度生成下一温度
function getNextTemp(prev, step) {
// 1. 日周期趋势:平均 27.5℃,振幅 2.5℃,周期 24 个时间步
const trend = 27.5 + 2.5 * Math.sin(2 * Math.PI * (step % 24) / 24);
// 2. 向趋势靠拢的漂移:alpha 控制靠拢速度
const alpha = 0.1;
const drift = (trend - prev) * alpha;
// 3. 高斯噪声:σ=0.2℃
const noise = gaussianRand() * 0.2;
let next = prev + drift + noise;
// 限制在 25–30℃
next = Math.min(Math.max(next, 25), 30);
return parseFloat(next.toFixed(2));
}
// 生成初始 12 点数据
function generateInitialData() {
const data = [];
for (let i = 0; i < 12; i++) {
currentTemp = getNextTemp(currentTemp, timeStep++);
data.push(currentTemp);
}
return data;
}
// x 轴标签
const labels = Array.from({ length: 12 }, (_, i) => i + 1);
// 创建 Chart.js 折线图
const ctxLine = document.getElementById('myAreaChart').getContext('2d');
const myAreaChart = new Chart(ctxLine, {
type: 'line',
data: {
labels: labels,
datasets: [{
label: '水温 (℃)',
data: generateInitialData(),
borderColor: 'rgba(75, 192, 192, 1)',
tension: 0.4,
fill: false
}]
},
options: {
responsive: true,
maintainAspectRatio: false,
animations: { x: { duration: 1000 }, y: { duration: 0 } },
scales: {
y: { min: 25, max: 30, type: 'linear' },
x: { type: 'linear' }
},
plugins: {
zoom: {
zoom: {
wheel: { enabled: true },
drag: { enabled: true },
mode: 'xy'
},
pan: { enabled: true, mode: 'xy' }
}
}
}
});
// 每 3 秒更新一次
setInterval(() => {
// 滑动窗口
myAreaChart.data.labels.shift();
myAreaChart.data.labels.push(myAreaChart.data.labels.slice(-1)[0] + 1);
// 计算新温度
currentTemp = getNextTemp(currentTemp, timeStep++);
myAreaChart.data.datasets[0].data.shift();
myAreaChart.data.datasets[0].data.push(currentTemp);
myAreaChart.update();
}, 3000);
</script>
</html>