PHP code example of alkoumi / filament-google-charts

1. Go to this page and download the library: Download alkoumi/filament-google-charts 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/ */

    

alkoumi / filament-google-charts example snippets


use Alkoumi\FilamentGoogleCharts\Widgets\LineChartWidget;

class SalesChartWidget extends LineChartWidget
{
    protected static ?string $heading = 'Monthly Sales';

    protected static ?int $sort = 1;

    protected static ?array $options = [
        'legend' => ['position' => 'bottom'],
        'colors' => ['#3b82f6', '#10b981'],
    ];

    protected function getData(): array
    {
        return [
            ['Month', 'Sales', 'Expenses'],
            ['Jan', 1000, 400],
            ['Feb', 1170, 460],
            ['Mar', 660, 1120],
            ['Apr', 1030, 540],
            ['May', 1200, 600],
            ['Jun', 1500, 700],
        ];
    }
}

use Alkoumi\FilamentGoogleCharts\Widgets\PieChartWidget;

class RegionalSalesWidget extends PieChartWidget
{
    protected static ?string $heading = 'Sales by Region';

    protected static ?int $sort = 2;

    protected int | string | array $columnSpan = 1;

    protected static ?array $options = [
        'pieHole' => 0.4,
        'colors' => ['#3b82f6', '#10b981', '#f59e0b', '#ef4444'],
    ];

    protected function getData(): array
    {
        return [
            ['Region', 'Sales'],
            ['North', 1200],
            ['South', 900],
            ['East', 1500],
            ['West', 800],
        ];
    }
}

use Alkoumi\FilamentGoogleCharts\Widgets\DonutChartWidget;

class DemoDonutChart extends DonutChartWidget
{
    protected static ?string $heading = 'Donut chart';

    protected static ?int $sort = 2;

    protected static ?float $pieHole = 0.5;

    protected static ?array $options = [
        'legend' => [
            'position' => 'top',
        ],
        'height' => 400,
    ];

    protected function getData(): array
    {
        return [
            ['Label', 'Aggregate'],
            ['Col1', 17.2],
            ['Col2', 23.7],
            ['Col3', 11.1],
        ];
    }
}

use Alkoumi\FilamentGoogleCharts\Widgets\GeoChartWidget;

class GeoSalesWidget extends GeoChartWidget
{
    protected static ?string $heading = 'Sales by Country';

    protected static ?int $sort = 3;

    protected int | string | array $columnSpan = 'full';

    protected static ?array $options = [
        'colorAxis' => [
            'colors' => ['#bbdefb', '#1976d2'],
        ],
    ];

    protected function getData(): array
    {
        return [
            ['Country', 'Sales'],
            ['United States', 5000],
            ['Germany', 3000],
            ['Brazil', 2500],
            ['Canada', 2000],
            ['France', 1800],
            ['United Kingdom', 1500],
            ['Australia', 1200],
            ['Japan', 1000],
            ['Egypt', 800],
            ['Saudi Arabia', 600],
        ];
    }
}

protected static ?string $pollingInterval = '10s';

protected static ?string $pollingInterval = null;

protected static ?array $options = [
        'legend' => [
            'position' => 'bottom',
        ],
        'height' => 300,
    ];
bash
php artisan vendor:publish --tag=filament-google-charts-config
bash
php artisan vendor:publish --tag=filament-google-charts-views