Show a year of activity at a glance
Yann Bertrand brought Apple Watch workouts into Grafana. Compare the monthly shape with the total for the year.
Yann Bertrand · Grafana · Source post
Show monthly distribution alongside period totals
An independent web example inspired by the original reference.
Switch the year, then press any month to check its record.
Implementation steps
- Aggregate records by month into 12 values in the same unit. The sample uses monthly exercise time.
- When the year changes, update the total and bars from the same data. Use a shared scale for year-to-year comparison.
- Selecting a month shows its value. Don't rely on bar length alone; make months checkable by keyboard too.
Acceptance check
Totals match monthly values, and identical values render at the same height in either year.
View sample code
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Show monthly distribution alongside period totals</title>
<style>
* { box-sizing: border-box; }
body {
margin: 0;
padding: 16px;
background: #23232a;
color: #f4f0ea;
font: 16px/1.6 system-ui, sans-serif;
}
label, output, strong, audio, progress { display: block; margin: 6px 0; }
input, select, button { max-width: 100%; font: inherit; }
input, select { padding: 4px 7px; }
button {
margin: 4px 0;
padding: 5px 12px;
cursor: pointer;
border: 1px solid #b5a399;
border-radius: 6px;
}
:focus-visible { outline: 3px solid #ffad73; outline-offset: 2px; }
audio { width: 100%; }
[hidden] { display: none !important; }
#months { display: flex; gap: 3px; align-items: end; }
#months button {
flex: 1;
min-width: 0;
padding: 0;
font-size: 12px;
color: #18392e;
background: #a5dbc5;
}
</style>
</head>
<body>
<label>Year <select id="year"><option>2025</option><option>2026</option></select></label>
<strong id="total"></strong>
<div id="months" aria-label="Monthly exercise hours"></div>
<output id="value"></output>
<script>
const records = {
2025: [3,5,2,7,4,8,6,5,3,7,8,9],
2026: [5,6,3,5,8,9,4,6,7,8,5,6]
};
const year = document.querySelector('#year');
function render() {
const data = records[year.value];
const sum = data.reduce((a, b) => a + b, 0);
document.querySelector('#total').textContent = 'Year total: ' + sum + ' hours';
const months = document.querySelector('#months');
months.replaceChildren();
document.querySelector('#value').textContent = 'Select a month';
data.forEach((hours, i) => {
const button = document.createElement('button');
const label = (i + 1) + ': ' + hours + ' hours';
button.style.height = (24 + hours * 5) + 'px';
button.textContent = i + 1;
button.setAttribute('aria-label', label);
button.onclick = () => { document.querySelector('#value').textContent = label; };
months.append(button);
});
}
year.onchange = render;
render();
</script>
</body>
</html>Save as index.html and open in a browser to run it locally.