Demonstrates how to create widgets on dashboard, mimicking the behavior of Google Analytics.
The main logic lives in two charts that we have created - VisitorsPerCountry
and VisitorsChart
:
flowframe/laravel-trend
that's documented here
All of this includes a clever usage of Filament charts/widgets and custom Livewire components. So here's how that looks in code:
Our first chart - VisitorsChart, which displays historical data:
VisitorsChart
// Our default filter is "year"public ?string $filter = 'year'; // This chart is not interactive, so we don't need to poll itprotected static ?string $pollingInterval = null; // We have a custom view for this chartprotected static string $view = 'filament.widgets.visitors-chart'; // Our custom view has a variable $totalVisitors, so we need to define itpublic int $totalVisitors = 0; // We have a dropdown filter, so we need to define the optionsprotected function getFilters(): ?array{ return [ 'year' => 'This year', 'week' => 'This week', 'month' => 'Last month', 'half_year' => 'Last 6 months', ];} // This sets the data for the chartprotected function getData(): array{ // ...