# 身体数据

身高：170cm

### 统计体重变化

使用 https://www.chartjs.org/

<div>
  <canvas id="weightChart"></canvas>
</div>

<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>

<script>
const weightData = [
    { date: '2020-05-15', weight: 73.0 },
    { date: '2020-11-04', weight: 78.6 },
    { date: '2021-04-16', weight: 76.6 },
    { date: '2021-09-05', weight: 69.7 },
    { date: '2021-10-27', weight: 73.8 },
    { date: '2021-11-02', weight: 73.4 },
    { date: '2021-12-16', weight: 76.0 },
    { date: '2022-02-22', weight: 77.0 },
    { date: '2022-04-17', weight: 77.1 },
    { date: '2023-05-06', weight: 73.5 },
    { date: '2024-03-11', weight: 82.2 },
    { date: '2024-03-25', weight: 81.7 },
    { date: '2024-04-01', weight: 81.4 },
    { date: '2024-04-06', weight: 81.5 },
    { date: '2025-07-30', weight: 67.0 },
    { date: '2025-08-06', weight: 65.6 },
    { date: '2025-08-21', weight: 65.2 },
    { date: '2025-09-10', weight: 64.6 },
    { date: '2025-09-21', weight: 65.0 },
    { date: '2025-11-03', weight: 67.1 },
    { date: '2025-11-23', weight: 67.8 },
    { date: '2025-12-12', weight: 67.9 },
    { date: '2026-01-17', weight: 71 },
    { date: '2026-02-27', weight: 74 },
    { date: '2026-03-15', weight: 71.9 },
    { date: '2026-04-06', weight: 73.3 },
    { date: '2026-05-11', weight: 72.3 },
    { date: '2026-06-04', weight: 71.5 },
    { date: '2026-07-08', weight: 72 },
    { date: '2026-08-09', weight: 74.2 },
    { date: '2026-09-02', weight: 73.85 },
  ];

  const ctx = document.getElementById('weightChart');

  // Extract dates and weights from weightData
  const labels = weightData.map(item => item.date);
  const weights = weightData.map(item => item.weight);

  new Chart(ctx, {
    type: 'line',
    data: {
      labels: labels,
      datasets: [{
        label: 'Weight (kg)',
        data: weights,
        borderColor: 'rgb(75, 192, 192)',
        backgroundColor: 'rgba(75, 192, 192, 0.2)',
        borderWidth: 2,
        fill: true,
        tension: 0.1
      }]
    },
    options: {
      responsive: true,
      plugins: {
        legend: {
          display: true
        }
      },
      scales: {
        y: {
          beginAtZero: false,
          title: {
            display: true,
            text: 'Weight (kg)'
          }
        },
        x: {
          title: {
            display: true,
            text: 'Date'
          }
        }
      }
    }
  });
</script>


相关：[[lab-tests|lab-tests]]
