PHP code example of eightynine / filament-advanced-widgets

1. Go to this page and download the library: Download eightynine/filament-advanced-widgets library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

eightynine / filament-advanced-widgets example snippets



use EightyNine\FilamentAdvancedWidget\AdvancedStatsOverviewWidget as BaseWidget;
use EightyNine\FilamentAdvancedWidget\AdvancedStatsOverviewWidget\Stat;

class GeneralStatsOverviewWidget extends BaseWidget
{
    protected static ?string $pollingInterval = null;

    protected function getStats(): array
    {
        return [
            Stat::make('Total Users', "124k")->icon('heroicon-o-user')
                ->backgroundColor('info')
                ->progress(69)
                ->progressBarColor('success')
                ->iconBackgroundColor('success')
                ->chartColor('success')
                ->iconPosition('start')
                ->description('The users in this period')
                ->descriptionIcon('heroicon-o-chevron-up', 'before')
                ->descriptionColor('success')
                ->iconColor('success'),
            Stat::make('Total Posts', "1.2k")->icon('heroicon-o-newspaper')
                ->description('The posts in this period')
                ->descriptionIcon('heroicon-o-chevron-up', 'before')               
                ->descriptionColor('primary')
                ->iconColor('warning'),
            Stat::make('Total Comments', "23.4k")->icon('heroicon-o-chat-bubble-left-ellipsis')
                ->description("The comments in this period")
                ->descriptionIcon('heroicon-o-chevron-down', 'before')
                ->descriptionColor('danger')
                ->iconColor('danger')
        ];
    }
}

use EightyNine\FilamentAdvancedWidget\AdvancedStatsOverviewWidget\Stat;

Stat::make('Total Users', "124k")
    ->icon('heroicon-o-user')                             // The icon to display on stat
    ->backgroundColor('info')                             // The background color of the stat
    ->progress(69)                                        // Shows progress bar below the stat(0-100)
    ->progressBarColor('success')                         // The color of the progress bar    
    ->iconBackgroundColor('success')                      // The background color of the icon
    ->labelColor('success')                               // The color of the label
    ->textColor('success', 'success', 'info')             // The color of the text(label, value, description)
    ->valueColor('success')                               // The color of the value
    ->chartColor('success')                               // The color of the chart
    ->iconPosition('start')                               // The position of the icon (start, end)
    ->description('The users in this period')             // The description of the stat
    ->descriptionIcon('heroicon-o-chevron-up', 'before')  // The icon to display next with the description (before, after)
    ->descriptionColor('success')                         // The color of the description
    ->iconColor('success')                                // The color of the icon
    ->chart([12,34,22,11])                                // The data for the chart on the stat
    ...                                                   // YOu can use the default filament customizations



use EightyNine\FilamentAdvancedWidget\AdvancedChartWidget;

class MonthlyUsersChart extends AdvancedChartWidget
{

    protected static ?string $heading = '187.2k';
    protected static string $color = 'info';
    protected static ?string $icon = 'heroicon-o-chart-bar';
    protected static ?string $iconColor = 'info';
    protected static ?string $iconBackgroundColor = 'info';
    protected static ?string $label = 'Monthly users chart';

    protected static ?string $badge = 'new';
    protected static ?string $badgeColor = 'success';
    protected static ?string $badgeIcon = 'heroicon-o-check-circle';
    protected static ?string $badgeIconPosition = 'after';
    protected static ?string $badgeSize = 'xs';


    public ?string $filter = 'today';

    protected function getFilters(): ?array
    {
        return [
            'today' => 'Today',
            'week' => 'Last week',
            'month' => 'Last month',
            'year' => 'This year',
        ];
    }

    protected function getData(): array
    {
        return [
            'datasets' => [
                [
                    'label' => 'Blog posts created',
                    'data' => [0, 10, 5, 2, 21, 32, 45, 74, 65, 45, 77, 89],
                ],
            ],
            'labels' => ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
        ];
    }

    protected function getType(): string
    {
        return 'line';
    }
}



protected static ?string $heading = '187.2k';                       // The heading of the chart
protected static string $color = 'info';                            // The color of the chart
protected static ?string $icon = 'heroicon-o-chart-bar';            // The icon to display on the chart
protected static ?string $iconColor = 'info';                       // The color of the icon
protected static ?string $iconBackgroundColor = 'info';             // The background color of the icon
protected static ?string $label = 'Monthly users chart';            // The label of the chart
protected static ?string $badge = 'new';                            // The badge to display on the chart
protected static ?string $badgeColor = 'success';                   // The color of the badge
protected static ?string $badgeIcon = 'heroicon-o-check-circle';    // The icon to display on the badge
protected static ?string $badgeIconPosition = 'after';              // The position of the icon on the badge (before, after)
protected static ?string $badgeSize = 'xs';                         // The size of the badge