Skip to main content

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:
This command will create a new StatsOverview.php file. Open it, and return Stat instances from the getStats() method:
Now, check out your widget in the dashboard.

Adding a description and icon to a stat

You may add a description() to provide additional information, along with a descriptionIcon():
The 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 using extraAttributes():
In this example, we are deliberately escaping the $ in $dispatch() since this needs to be passed directly to the HTML, it is not a PHP variable.

Adding a chart to a stat

You may also add or chain a chart() to each stat to provide historical data. The chart() method accepts an array of data points to plot:

Styling stat charts in a theme

Chart.js paints a stat’s chart onto a <canvas>, so its line cannot be reached from a stylesheet. A custom theme is CSS only, so Filament exposes the shape of that line as CSS custom properties, which you may set on .fi-wi-stats-overview-stat, or on any element above it to cover every stat in the panel at once:
--stat-chart-border-width thickens the line, --stat-chart-line-tension curves it, from 0 for straight segments up to 1, and --stat-chart-fill shades the area beneath it, accepting start, end, origin or stack, as well as none to leave the line bare. These values are handed to Chart.js rather than used by the browser, so they are plain numbers and keywords, without units. If you set one to something Chart.js cannot use, it is ignored and the chart keeps its default. They are also read again whenever the color scheme changes, so you may give light and dark mode different values. The chart takes its colors from the color of the stat. To change them in a theme, style the .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:
Alternatively, you may disable polling altogether:

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:
If you need to dynamically generate the heading or description text, you can instead override the getHeading() and getDescription() methods: