mirror of https://github.com/veypi/OneAuth.git
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
125 lines
3.0 KiB
HTML
125 lines
3.0 KiB
HTML
<!doctype html>
|
|
<html>
|
|
<head>
|
|
<title>CPU 负载图</title>
|
|
</head>
|
|
<style>
|
|
body {
|
|
font-family: Arial, sans-serif;
|
|
margin: 0;
|
|
padding: 0;
|
|
display: flex;
|
|
justify-content: center;
|
|
align-items: center;
|
|
height: 100vh;
|
|
background-color: #f4f4f9;
|
|
}
|
|
.chart-container {
|
|
width: 80%;
|
|
max-width: 600px;
|
|
background: white;
|
|
border-radius: 8px;
|
|
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
|
|
padding: 20px;
|
|
}
|
|
.chart-title {
|
|
text-align: center;
|
|
font-size: 18px;
|
|
margin-bottom: 20px;
|
|
}
|
|
canvas {
|
|
display: block;
|
|
width: 100%;
|
|
height: auto;
|
|
}
|
|
</style>
|
|
<body>
|
|
<div class="chart-container">
|
|
<div class="chart-title">CPU 负载 (%)</div>
|
|
<canvas id="cpuChart" width="600" height="300"></canvas>
|
|
</div>
|
|
</body>
|
|
<script>
|
|
// 初始化 CPU 负载数据
|
|
cpuLoadData = [];
|
|
|
|
// 获取 Canvas 上下文
|
|
const canvas = $node.querySelector("#cpuChart");
|
|
const ctx = canvas.getContext("2d");
|
|
|
|
// 绘制图表
|
|
drawChart = () => {
|
|
const width = canvas.width;
|
|
const height = canvas.height;
|
|
|
|
// 清空画布
|
|
ctx.clearRect(0, 0, width, height);
|
|
|
|
// 设置图表样式
|
|
ctx.strokeStyle = "#007bff";
|
|
ctx.lineWidth = 2;
|
|
ctx.fillStyle = "#007bff";
|
|
|
|
// 绘制坐标轴
|
|
ctx.beginPath();
|
|
ctx.moveTo(30, 10);
|
|
ctx.lineTo(30, height - 10);
|
|
ctx.lineTo(width - 10, height - 10);
|
|
ctx.stroke();
|
|
|
|
// 绘制刻度和标签
|
|
const maxValue = 100; // 最大负载值为 100%
|
|
const step = 20;
|
|
for (let i = 0; i <= maxValue; i += step) {
|
|
const y = height - 10 - ((i / maxValue) * (height - 20));
|
|
ctx.fillText(i + "%", 5, y + 5);
|
|
ctx.beginPath();
|
|
ctx.moveTo(25, y);
|
|
ctx.lineTo(30, y);
|
|
ctx.stroke();
|
|
}
|
|
|
|
// 绘制折线图
|
|
if (cpuLoadData.length > 0) {
|
|
const dataLength = cpuLoadData.length;
|
|
const xStep = (width - 40) / dataLength;
|
|
|
|
ctx.beginPath();
|
|
ctx.moveTo(30, height - 10 - ((cpuLoadData[0] / maxValue) * (height - 20)));
|
|
|
|
for (let i = 1; i < dataLength; i++) {
|
|
const x = 30 + i * xStep;
|
|
const y = height - 10 - ((cpuLoadData[i] / maxValue) * (height - 20));
|
|
ctx.lineTo(x, y);
|
|
}
|
|
|
|
ctx.stroke();
|
|
}
|
|
};
|
|
|
|
// 更新 CPU 负载数据并重新绘制
|
|
updateCpuLoad = () => {
|
|
// 模拟生成随机 CPU 负载数据
|
|
const newLoad = Math.random() * 100;
|
|
cpuLoadData.push(newLoad);
|
|
|
|
// 限制数据点数量(最多显示 30 个点)
|
|
if (cpuLoadData.length > 30) {
|
|
cpuLoadData.shift();
|
|
}
|
|
|
|
// 重新绘制图表
|
|
drawChart();
|
|
};
|
|
|
|
// 初始化定时器,每秒更新一次数据
|
|
intervalId = setInterval(updateCpuLoad, 1000);
|
|
</script>
|
|
<script>
|
|
// 页面卸载时清除定时器
|
|
window.addEventListener("beforeunload", () => {
|
|
clearInterval(intervalId);
|
|
});
|
|
</script>
|
|
</html>
|