?php
namespace App\Filament\Widgets;
use App\Models\Customer;
use Filament\Widgets\ChartWidget;
use Flowframe\Trend\Trend;
use Flowframe\Trend\TrendValue;
class CustomerChart extends ChartWidget
{
protected static ?string $heading = 'Customer Growth Chart';
protected static ?int $sort = 2;
protected static ?string $maxHeight = '300px';
protected int | string | array $columnSpan = 'full';
protected static ?array $options = [
'plugins' => [
'legend' => [
'display' => false,
],
],
];
protected function getData(): array
{
$data = Trend::model(Customer::class)
->between(
start: now()->subYear(),
end: now(),
)
->perMonth()
->count();
return [
//
'datasets' => [
[
'label' => 'Customers',
'data' => $data->map(fn (TrendValue $value) => $value->aggregate),
],
],
'labels' => $data->map(fn (TrendValue $value) => $value->date),
];
}
protected function getType(): string
{
return 'line';
}
}
?php
namespace App\Filament\Widgets;
use App\Models\Customer;
use Filament\Widgets\ChartWidget;
use Flowframe\Trend\Trend;
use Flowframe\Trend\TrendValue;
class CustomerChart extends ChartWidget
{
protected static ?string $heading = 'Customer Growth Chart';
protected static ?int $sort = 2;
protected static ?string $maxHeight = '300px';
protected int | string | array $columnSpan = 'full';
protected static ?array $options = [
'plugins' => [
'legend' => [
'display' => false,
],
],
];
protected function getData(): array
{
$data = Trend::model(Customer::class)
->between(
start: now()->subYear(),
end: now(),
)
->perMonth()
->count();
return [
//
'datasets' => [
[
'label' => 'Customers',
'data' => $data->map(fn (TrendValue $value) => $value->aggregate),
],
],
'labels' => $data->map(fn (TrendValue $value) => $value->date),
];
}
protected function getType(): string
{
return 'line';
}
}