// Carga asíncrona de las métricas del ciclo actual document.addEventListener('DOMContentLoaded', async () => { try { const response = await fetch('/index.php?route=reports/categorySummary'); const data = await response.json(); const ctx = document.getElementById('categoryChart').getContext('2d'); new Chart(ctx, { type: 'doughnut', data: { labels: data.map(item => item.category_name), datasets: [{ data: data.map(item => item.total_spent), backgroundColor: ['#0d6efd', '#20c997', '#ffc107', '#dc3545', '#6610f2', '#fd7e14'], borderWidth: 0 }] }, options: { responsive: true, maintainAspectRatio: false, plugins: { legend: { position: 'bottom', labels: { color: '#adb5bd' } } } } }); } catch (error) { console.error("Error cargando gráficos:", error); } });