base commit
This commit is contained in:
48
app/Filament/Widgets/DepartmentDistributionChart.php
Normal file
48
app/Filament/Widgets/DepartmentDistributionChart.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?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(),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user