48 lines
1.3 KiB
PHP
48 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Widgets;
|
|
|
|
use App\Models\Journalist;
|
|
use Filament\Widgets\ChartWidget;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
class JournalistRegistrationChart extends ChartWidget
|
|
{
|
|
protected ?string $heading = 'Tren Pertambahan Jurnalis';
|
|
|
|
protected static ?int $sort = 8;
|
|
|
|
protected int|string|array $columnSpan = 'full';
|
|
|
|
protected function getData(): array
|
|
{
|
|
$data = Journalist::query()
|
|
->select(
|
|
DB::raw('COUNT(*) as count'),
|
|
DB::raw("DATE_FORMAT(created_at, '%Y-%m') as month")
|
|
)
|
|
->where('created_at', '>=', now()->subMonths(6))
|
|
->groupBy('month')
|
|
->orderBy('month')
|
|
->get();
|
|
|
|
return [
|
|
'datasets' => [
|
|
[
|
|
'label' => 'Jurnalis Baru',
|
|
'data' => $data->pluck('count')->toArray(),
|
|
'fill' => 'start',
|
|
'borderColor' => '#6366F1',
|
|
'backgroundColor' => 'rgba(99, 102, 241, 0.1)',
|
|
],
|
|
],
|
|
'labels' => $data->pluck('month')->map(fn ($m) => \Carbon\Carbon::createFromFormat('Y-m', $m)->translatedFormat('M Y'))->toArray(),
|
|
];
|
|
}
|
|
|
|
protected function getType(): string
|
|
{
|
|
return 'line';
|
|
}
|
|
}
|