main

filamentphp/demo

Last updated at: 29/12/2023 09:42

CustomersChart.php

TLDR

This file defines a class called CustomersChart which extends a ChartWidget class. It provides a line chart widget that displays the total number of customers over the months of a year.

Classes

CustomersChart

This class extends ChartWidget and represents a line chart widget that displays the total number of customers over the months of a year. It defines two static variables, $heading and $sort, and two protected methods, getType() and getData(). The getType() method returns the chart type as a string, and the getData() method returns an array with the chart data.

<?php

namespace App\Filament\Widgets;

use Filament\Widgets\ChartWidget;

class CustomersChart extends ChartWidget
{
    protected static ?string $heading = 'Total customers';

    protected static ?int $sort = 2;

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

    protected function getData(): array
    {
        return [
            'datasets' => [
                [
                    'label' => 'Customers',
                    'data' => [4344, 5676, 6798, 7890, 8987, 9388, 10343, 10524, 13664, 14345, 15753, 17332],
                    'fill' => 'start',
                ],
            ],
            'labels' => ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
        ];
    }
}