Introduction
Filament comes with a “stats overview” widget template, which you can use to display a number of different stats in a single widget, without needing to write a custom view. Start by creating a widget with the command:StatsOverview.php file. Open it, and return Stat instances from the getStats() method:
Adding a description and icon to a stat
You may add adescription() to provide additional information, along with a descriptionIcon():
descriptionIcon() method also accepts a second parameter to put the icon before the description instead of after it:
Changing the color of the stat
You may also give stats a color:Adding extra HTML attributes to a stat
You may also pass extra HTML attributes to stats usingextraAttributes():
$ in $dispatch() since this needs to be passed directly to the HTML, it is not a PHP variable.
Setting a placeholder for a stat
Sometimes a stat’s value may not be available — for example, when a dashboard has nothing to show for a specific period. You can useplaceholder() to define what should be displayed instead when the value is blank:
blank() helper. For example, null and empty strings are blank, while 0 and '0' are not.
Setting a default placeholder globally
If you’d like every stat in your app to fall back to the same placeholder by default, you can use the staticconfigureUsing() method in a service provider’s boot() method:
placeholder() themselves.
Adding a chart to a stat
You may also add or chain achart() to each stat to provide historical data. The chart() method accepts an array of data points to plot:
Styling stat charts in a theme
To style stat charts from a custom theme, set these CSS custom properties on.fi-wi-stats-overview-stat or a parent element:
--stat-chart-border-width: The line thickness.--stat-chart-line-tension: The curvature, from0for straight segments to1.--stat-chart-fill: The fill target:start,end,origin, orstack. Usenoneto disable the fill.
.fi-wi-stats-overview-stat-chart-bg-color and .fi-wi-stats-overview-stat-chart-border-color elements with an ordinary color declaration:
These properties only affect the charts inside stats. Chart widgets are styled with their own set, prefixed
--chart-.Live updating stats (polling)
By default, stats overview widgets refresh their data every 5 seconds. To customize this, you may override the$pollingInterval property on the class to a new interval:
Disabling lazy loading
By default, widgets are lazy-loaded. This means that they will only be loaded when they are visible on the page. To disable this behavior, you may override the$isLazy property on the widget class:
Adding a heading and description
You may also add heading and description text above the widget by overriding the$heading and $description properties:
getHeading() and getDescription() methods: