49 lines
1.2 KiB
PHP
49 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 ?string $heading = 'Employees by Department';
|
|
|
|
protected int | string | array $columnSpan = 1;
|
|
|
|
protected function getType(): string
|
|
{
|
|
return 'doughnut';
|
|
}
|
|
|
|
protected function getData(): array
|
|
{
|
|
$departments = Department::query()
|
|
->withCount('employees')
|
|
->orderBy('name')
|
|
->get();
|
|
|
|
return [
|
|
'datasets' => [
|
|
[
|
|
'label' => 'Employees',
|
|
'data' => $departments->pluck('employees_count')->all(),
|
|
'backgroundColor' => [
|
|
'#3b82f6',
|
|
'#10b981',
|
|
'#f59e0b',
|
|
'#ef4444',
|
|
'#8b5cf6',
|
|
'#06b6d4',
|
|
'#84cc16',
|
|
'#f97316',
|
|
],
|
|
],
|
|
],
|
|
'labels' => $departments->pluck('name')->all(),
|
|
];
|
|
}
|
|
}
|