Skip to main content

Introduction

Stats overview widgets provide a clean, organized way to display key metrics and statistics in your Filament application. These widgets are perfect for dashboards, showing important numbers at a glance with optional trend indicators and inline charts. Each stats overview widget can display multiple stat cards in a responsive grid layout, making it easy to showcase various metrics together.

Creating a Stats Overview Widget

Generate a stats overview widget using the Artisan command:
This creates a widget class in app/Filament/Widgets/:

Creating Stats

Each stat is created using the Stat::make() method with a label and value:

Dynamic Stat Values

Generate stat values from your database:

Formatting Numbers

Format large numbers for readability:

Adding Descriptions

Provide context with descriptions and trend indicators:

Description Icon Position

Place icons before the description:

Multiple Descriptions

Show multiple trend indicators:

Stat Colors

Apply colors to emphasize stat meaning:
Available colors: primary, success, warning, danger, info, gray.

Dynamic Colors

Set colors based on conditions:

Adding Charts to Stats

Display trend charts within stat cards:
The chart displays as a small line graph showing the trend.

Generating Chart Data

Use the laravel-trend package to generate chart data:

Extra HTML Attributes

Add custom attributes for styling or interactions:
Note: Escape the $ in $dispatch() with \$ since this is passed to HTML, not evaluated as PHP.

Widget Heading and Description

Add a heading and description above the stats:
Or use methods for dynamic values:

Live Updating (Polling)

Stats widgets refresh every 5 seconds by default:

Lazy Loading

Stats widgets are lazy-loaded by default. Disable if needed:

Stats Grid Layout

The widget automatically arranges stats in a responsive grid. The grid adapts based on the number of stats:
  • 1-2 stats: Full width
  • 3+ stats: 3 columns on large screens
  • Automatically adjusts to 4 columns if the count is optimal

Customizing Grid Columns

Override the $columns property to customize the grid:

Common Stat Patterns

Revenue Statistics

User Growth

Conversion Metrics

Inventory Status

Using Stats with Dashboard Filters

Access dashboard filters to filter stat data:

Best Practices

  1. Keep Numbers Meaningful: Format large numbers (use ‘k’ for thousands, ‘M’ for millions)
  2. Show Trends: Include descriptions with percentage changes or counts
  3. Use Appropriate Colors: Green for positive metrics, red for negative, gray for neutral
  4. Add Context: Descriptions should explain what the number represents
  5. Include Charts: Small charts help visualize trends at a glance
  6. Limit Stats Count: 3-6 stats per widget for optimal readability
  7. Update Regularly: Use polling for real-time data or cache expensive queries
  8. Consistent Formatting: Use the same number format across related stats
  9. Icon Consistency: Use trending-up for positive, trending-down for negative
  10. Responsive Design: Test stats display on different screen sizes

Performance Optimization

For expensive stat calculations, use caching:

Next Steps