Adding model data to the chart property of the stat component
This data is randomly entered into the array to generate a decorative graphic in the widget, or the Model information can be used.
The documentation or tutorials I have searched on the internet are examples with random data and not with models. I don't know how to apply it
3 Replies
you can replace this array with your data
just make sure you query will return a flat array
also chack this one on the docs
https://filamentphp.com/docs/3.x/widgets/charts#generating-chart-data-from-an-eloquent-model
Thanks for your help, I solved it
protected function getStats(): array
{
return [
Stat::make('Students', Student::where('active', true)->count())
->label(__('Students'))
->color('success')
->chart($this->getData())
->icon('mdi-account-school')
->description(__('Total students'))
];
}