Overview
TheHealthStats component displays weight measurements over time using Chart.js for interactive data visualization. It prepares data for line charts showing weight trends and historical patterns.
Namespace: App\Livewire\History\HealthStatsRoute:
GET /stats
Properties
Array of formatted dates for the X-axis (e.g.,
['01/01/2024', '05/01/2024'])Array of weight values in kilograms for the Y-axis (e.g.,
[75.5, 74.2, 73.8])Methods
mount()
Loads all weight measurements for the current user and prepares chart data.app/Livewire/History/HealthStats.php:14-28
d/m/Y (e.g., 25/01/2024) for display on the chart.
render()
Renders the statistics view with chart data.app/Livewire/History/HealthStats.php:30-33
Chart.js Integration
The component passes data to the Blade view, which uses Chart.js to render the chart:Example Chart Data
If a user has these weight records:| Date | Weight |
|---|---|
| 2024-01-01 | 75.5 kg |
| 2024-01-08 | 74.8 kg |
| 2024-01-15 | 74.2 kg |
| 2024-01-22 | 73.9 kg |
Future Enhancements
The component currently only visualizes weight data. Potential additions:- Blood pressure trends - Systolic and diastolic over time
- Heart rate trends - BPM patterns and anomalies
- Exercise frequency - Activity counts per week/month
- Appointment history - Timeline of medical visits
- Date range filtering - View specific time periods (last 30/90 days, year)
- Goal tracking - Compare actual vs target weight
Viewer Mode Support
The component currently usesauth()->id() directly. To support viewer mode:
Dependencies
- MeasurementWeight Model - For weight data
- Chart.js - JavaScript charting library (included in Blade view)
- Carbon - For date formatting (via Laravel)
Related Components
HealthHistory Component
View detailed list of all records
MeasurementWeight Model
Weight measurement data model
