Files

89 lines
4.3 KiB
HTML
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>体重曲线 · 12 周</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/4.4.1/chart.umd.min.js"></script>
<style>
:root { --ink:#1f2933; --muted:#6b7280; --grid:#e5e7eb; --line:#2563eb; }
* { box-sizing: border-box; }
body { margin:0; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif; background:#f8fafc; color: var(--ink); }
.wrap { max-width: 920px; margin: 0 auto; padding: 24px 16px 48px; }
h1 { font-size: 20px; margin: 0 0 4px; }
.sub { color: var(--muted); font-size: 13px; }
.card { background:#fff; border:1px solid var(--grid); border-radius:12px; padding:16px; box-shadow:0 1px 2px rgba(0,0,0,.04); }
.chart-box { position: relative; height: 420px; }
.meta { display:flex; gap:24px; flex-wrap:wrap; margin-top:16px; font-size:13px; color: var(--muted); }
.meta b { color: var(--ink); }
.hint { margin-top:16px; font-size:12px; color: var(--muted); line-height:1.7; background:#f1f5f9; border-radius:8px; padding:10px 12px; }
code { background:#eef2f7; padding:1px 5px; border-radius:4px; font-size:12px; }
</style>
</head>
<body>
<div class="wrap">
<header>
<h1>体重曲线 · 12 周</h1>
<div class="sub">167 cm | 起始 73 kg | 目标 67 kg(BMI 24.0)</div>
</header>
<div class="card">
<div class="chart-box"><canvas id="chart"></canvas></div>
<div class="meta">
<div>起始体重:<b id="startW">—</b></div>
<div>最新体重:<b id="latestW">—</b></div>
<div>累计变化:<b id="deltaW">—</b></div>
</div>
</div>
<div class="hint">
<b>怎么用</b>:找到下面的 <code>LABELS</code> 与 <code>ACTUAL</code> 两个数组,按周填入日期和体重即可(未称重的周留 <code>null</code>)。
灰色带是计划的<b>目标区间</b>,蓝线是你填的<b>实际体重</b>;蓝线落在灰带内即为达标。
</div>
</div>
<script>
// ====== 在这里填数据 ======
const LABELS = ["起始","第1周","第2周","第3周","第4周","第5周","第6周","第7周","第8周","第9周","第10周","第11周","第12周"];
const ACTUAL = [73.0, null, null, null, null, null, null, null, null, null, null, null, null]; // 实际体重,未称重填 null
// ==========================
const TARGET_LOW = [null, 72.2, 71.7, 71.2, 70.7, 70.2, 69.7, 69.2, 68.7, 68.2, 67.7, 67.2, 66.7];
const TARGET_HIGH = [null, 72.8, 72.3, 71.8, 71.3, 70.8, 70.3, 69.8, 69.3, 68.8, 68.3, 67.8, 67.3];
new Chart(document.getElementById('chart').getContext('2d'), {
type: 'line',
data: {
labels: LABELS,
datasets: [
{ label: '目标上限', data: TARGET_HIGH, borderColor: 'rgba(156,163,175,0)', pointRadius: 0, fill: '+1', backgroundColor: 'rgba(37,99,235,0.10)' },
{ label: '目标下限', data: TARGET_LOW, borderColor: 'rgba(156,163,175,0.9)', borderDash: [4,4], pointRadius: 0, fill: false },
{ label: '实际体重', data: ACTUAL, borderColor: '#2563eb', backgroundColor: '#2563eb', borderWidth: 2.5, tension: 0.25, pointRadius: 4, pointHoverRadius: 6, spanGaps: true }
]
},
options: {
responsive: true, maintainAspectRatio: false,
interaction: { mode: 'index', intersect: false },
plugins: {
legend: { labels: { filter: (i) => i.text !== '目标上限' } },
tooltip: { callbacks: { label: (c) => c.dataset.label + ':' + c.parsed.y + ' kg' } }
},
scales: {
y: { title: { display: true, text: '体重 (kg)' }, suggestedMin: 66, suggestedMax: 74, grid: { color: '#eef2f7' } },
x: { grid: { display: false } }
}
}
});
// 汇总
const nums = ACTUAL.filter((v) => v !== null);
const start = ACTUAL[0] != null ? ACTUAL[0] : null;
const latest = nums.length ? nums[nums.length - 1] : null;
document.getElementById('startW').textContent = start != null ? start.toFixed(1) + ' kg' : '—';
document.getElementById('latestW').textContent = latest != null ? latest.toFixed(1) + ' kg' : '—';
document.getElementById('deltaW').textContent =
start != null && latest != null ? (latest - start >= 0 ? '+' : '') + (latest - start).toFixed(1) + ' kg' : '—';
</script>
</body>
</html>