F
Filament12mo ago
krkmo

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
No description
3 Replies
Lara Zeus
Lara Zeus12mo ago
you can replace this array with your data
protected function getData(): array
{
return [
'datasets' => [
[
'label' => 'Blog posts created',
'data' => ModeName::....,
],
],
];
}
protected function getData(): array
{
return [
'datasets' => [
[
'label' => 'Blog posts created',
'data' => ModeName::....,
],
],
];
}
just make sure you query will return a flat array
krkmo
krkmoOP12mo ago
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')) ]; }
Want results from more Discord servers?
Add your server