diff --git a/app/Filament/Widgets/PopularNewsChart.php b/app/Filament/Widgets/PopularNewsChart.php new file mode 100644 index 0000000..1a7909f --- /dev/null +++ b/app/Filament/Widgets/PopularNewsChart.php @@ -0,0 +1,39 @@ +orderByDesc('views') + ->limit(10) + ->get(); + + return [ + 'datasets' => [ + [ + 'label' => 'Total Dilihat', + 'data' => $data->pluck('views')->toArray(), + 'backgroundColor' => '#EC4899', + ], + ], + 'labels' => $data->pluck('title')->map(fn ($t) => str($t)->limit(30))->toArray(), + ]; + } + + protected function getType(): string + { + return 'bar'; + } +} diff --git a/app/Filament/Widgets/VisitorTrafficChart.php b/app/Filament/Widgets/VisitorTrafficChart.php new file mode 100644 index 0000000..24ce400 --- /dev/null +++ b/app/Filament/Widgets/VisitorTrafficChart.php @@ -0,0 +1,47 @@ +select( + DB::raw('SUM(counter) as total'), + DB::raw("DATE_FORMAT(date, '%Y-%m-%d') as day") + ) + ->where('date', '>=', now()->subDays(30)) + ->groupBy('day') + ->orderBy('day') + ->get(); + + return [ + 'datasets' => [ + [ + 'label' => 'Total Kunjungan', + 'data' => $data->pluck('total')->toArray(), + 'fill' => 'start', + 'borderColor' => '#3B82F6', + 'backgroundColor' => 'rgba(59, 130, 246, 0.1)', + ], + ], + 'labels' => $data->pluck('day')->map(fn ($d) => \Carbon\Carbon::parse($d)->translatedFormat('d M'))->toArray(), + ]; + } + + protected function getType(): string + { + return 'line'; + } +}