Files
animethemes-server/app/Filament/Widgets/Auth/UserChart.php
T
2026-03-23 15:31:57 -03:00

66 lines
1.6 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Filament\Widgets\Auth;
use App\Filament\Widgets\BaseChartWidget;
use App\Models\Auth\User;
use App\Services\FlowframeTrend\TrendValue;
class UserChart extends BaseChartWidget
{
/**
* Chart Id.
*/
protected static ?string $chartId = 'usersChart';
/**
* Get the displayed label of the widget.
*/
protected function getHeading(): string
{
return __('filament.resources.label.users');
}
/**
* Chart options (series, labels, types, size, animations...)
* https://echarts.apache.org/en/option.html.
*/
protected function getOptions(): array
{
$data = $this->perMonth(User::class);
return [
'grid' => [
'top' => '10',
'left' => '0',
'bottom' => '0',
'right' => '0',
'containLabel' => true,
],
'xAxis' => [
'type' => 'category',
'boundaryGap' => true,
'data' => $data->map(fn (TrendValue $value): string => $this->translateDate($value->date)),
'axisLabel' => [
'interval' => 0,
],
],
'yAxis' => [
'type' => 'value',
],
'series' => [
[
'data' => $data->map(fn (TrendValue $value): mixed => $value->aggregate),
'type' => 'bar',
'label' => [
'show' => true,
],
],
],
];
}
}