From 1b5d77e37dbcdcfecf06e151dc4bb07c78e44d52 Mon Sep 17 00:00:00 2001 From: Dan Harrin Date: Tue, 5 Aug 2025 09:29:04 +0100 Subject: [PATCH] Update 03-charts.md --- packages/widgets/docs/03-charts.md | 51 +++++++++++------------------- 1 file changed, 19 insertions(+), 32 deletions(-) diff --git a/packages/widgets/docs/03-charts.md b/packages/widgets/docs/03-charts.md index a789c9df8d..da0a28f62e 100644 --- a/packages/widgets/docs/03-charts.md +++ b/packages/widgets/docs/03-charts.md @@ -172,52 +172,39 @@ use Filament\Forms\Components\DatePicker; use Filament\Schemas\Schema; use Filament\Widgets\ChartWidget\Concerns\HasFiltersSchema; -use HasFiltersSchema; - -public function filtersSchema(Schema $schema): Schema +class BlogPostsChart extends ChartWidget { - return $schema->components([ - DatePicker::make('date_start') - ->default( - now() - ->subDays(30) - ->format('Y-m-d') - ), - - DatePicker::make('date_end') - ->default( - now() - ->format('Y-m-d') - ), - ]); + use HasFiltersSchema; + + // ... + + public function filtersSchema(Schema $schema): Schema + { + return $schema->components([ + DatePicker::make('startDate') + ->default(now()->subDays(30)), + DatePicker::make('endDate') + ->default(now()), + ]); + } } ``` -The filter values are accessible via the `$this->filters` array. -You can use these values inside your `getData()` method: +The filter values are accessible via the `$this->filters` array. You can use these values inside your `getData()` method: ```php protected function getData(): array { - $dateStart = $this->filters['date_start']; - $dateEnd = $this->filters['date_end']; + $startDate = $this->filters['startDate'] ?? null; + $endDate = $this->filters['endDate'] ?? null; return [ - // + // ... ]; } ``` - +The `$this->filters` array will always reflect the current form data. Please note that this data is not validated, as it is available live and not intended to be used for anything other than querying the database. You must ensure that the data is valid before using it.