2025-05-10 22:53:50 +02:00

121 lines
4.5 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Padel Nivelles - Reports</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
body { font-family: Arial, sans-serif; background: #222831; color: #DFD0B8; margin: 2em; }
.charts-flex {
display: flex;
gap: 2em;
justify-content: center;
align-items: flex-start;
flex-wrap: wrap;
}
.chart-container.small-chart {
background: #393E46;
padding: 1em 1.2em;
border-radius: 8px;
margin-bottom: 1em;
min-width: 320px;
max-width: 350px;
flex: 1 1 320px;
box-sizing: border-box;
}
.chart-container.small-chart canvas {
max-width: 100%;
height: 260px !important;
width: 100% !important;
}
h2 { color: #948979; font-size: 1.1em; margin-bottom: 0.5em; }
a, button { color: #222831; background: #948979; border: none; padding: 0.7em 1.5em; border-radius: 4px; font-weight: bold; font-size: 1em; transition: background 0.2s; cursor: pointer; text-decoration: none; }
a:hover, button:hover { background: #7c765c; }
@media (max-width: 900px) {
.charts-flex { flex-direction: column; align-items: stretch; }
.chart-container.small-chart { max-width: 100%; min-width: 0; }
}
</style>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
</head>
<body>
<a href="/" style="margin-bottom: 2em; display: inline-block;">Back to Attendance</a>
<div class="charts-flex">
<div class="chart-container small-chart">
<h2>Attendance Count per Player</h2>
<canvas id="barChart" width="300" height="300"></canvas>
</div>
<div class="chart-container small-chart">
<h2>Player Attendance Share (Pie)</h2>
<canvas id="pieChart" width="300" height="300"></canvas>
</div>
</div>
<script>
fetch('/api/data').then(r => r.json()).then(data => {
const players = data.players;
const attendance = data.attendance;
// Calculate Yes counts per player
const yesCounts = Array(players.length).fill(0);
Object.entries(attendance).forEach(([key, value]) => {
if (value === true) {
const [date, colIdx] = key.split('|');
const idx = parseInt(colIdx);
if (idx < players.length) yesCounts[idx]++;
}
});
// Bar chart
new Chart(document.getElementById('barChart').getContext('2d'), {
type: 'bar',
data: {
labels: players,
datasets: [{
label: 'Number of Yes',
data: yesCounts,
backgroundColor: '#948979',
borderColor: '#222831',
borderWidth: 1
}]
},
options: {
plugins: { legend: { display: false } },
scales: {
y: { beginAtZero: true, ticks: { color: '#DFD0B8' }, grid: { color: '#393E46' } },
x: { ticks: { color: '#DFD0B8' }, grid: { color: '#393E46' } }
}
}
});
// Pie chart
const totalYes = yesCounts.reduce((a, b) => a + b, 0);
new Chart(document.getElementById('pieChart').getContext('2d'), {
type: 'pie',
data: {
labels: players,
datasets: [{
data: yesCounts,
backgroundColor: [
'#948979', '#DFD0B8', '#7c765c', '#393E46', '#222831', '#bfa181', '#b7b7a4', '#a7c957'
]
}]
},
options: {
plugins: {
legend: { labels: { color: '#DFD0B8' } },
tooltip: {
callbacks: {
label: function(context) {
const label = context.label || '';
const value = context.parsed;
const percent = totalYes ? ((value / totalYes) * 100).toFixed(1) : 0;
return label + ': ' + value + ' (' + percent + '%)';
}
}
}
}
}
});
});
</script>
</body>
</html>