= 0; $i--) { $month = Carbon::now()->subMonths($i); $startOfMonth = $month->copy()->startOfMonth(); $endOfMonth = $month->copy()->endOfMonth(); $total = Reservasii::whereBetween('tanggal', [$startOfMonth, $endOfMonth]) ->sum('total'); $count = Reservasii::whereBetween('tanggal', [$startOfMonth, $endOfMonth]) ->count(); $data[] = $total; $labels[] = $month->format('M Y'); $details[] = [ 'total' => $total, 'count' => $count, 'month' => $month->format('F Y') ]; } return [ 'datasets' => [ [ 'label' => 'Pendapatan', 'data' => $data, 'backgroundColor' => '#6B7280', 'borderColor' => '#4B5563', 'details' => $details, ], ], 'labels' => $labels, ]; } protected function getType(): string { return 'bar'; } protected function getOptions(): array { return [ 'scales' => [ 'y' => [ 'beginAtZero' => true, 'ticks' => [ 'callback' => 'function(value) { return "Rp " + value.toLocaleString("id-ID"); }' ], ], ], 'plugins' => [ 'tooltip' => [ 'enabled' => true, 'mode' => 'index', 'intersect' => false, 'callbacks' => [ 'title' => 'function(tooltipItems) { const details = tooltipItems[0].dataset.details[tooltipItems[0].dataIndex]; return details.month; }', 'label' => 'function(context) { const details = context.dataset.details[context.dataIndex]; return [ "Total Pendapatan: Rp " + details.total.toLocaleString("id-ID"), "Jumlah Reservasi: " + details.count ]; }' ], ], ], ]; } }