Files
hr/app/Filament/Widgets/DepartmentDistributionChart.php
2026-07-31 18:08:08 +05:00

52 lines
1.2 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Filament\Widgets;
use App\Models\Department;
use Filament\Widgets\ChartWidget;
class DepartmentDistributionChart extends ChartWidget
{
protected int | string | array $columnSpan = 1;
public function getHeading(): ?string
{
return __('hr.widgets.employees_by_department');
}
protected function getType(): string
{
return 'doughnut';
}
protected function getData(): array
{
$departments = Department::query()
->withCount('employees')
->orderBy('name')
->get();
return [
'datasets' => [
[
'label' => __('hr.widgets.employees'),
'data' => $departments->pluck('employees_count')->all(),
'backgroundColor' => [
'#3b82f6',
'#10b981',
'#f59e0b',
'#ef4444',
'#8b5cf6',
'#06b6d4',
'#84cc16',
'#f97316',
],
],
],
'labels' => $departments->pluck('name')->all(),
];
}
}