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.