main

filamentphp/demo

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

OrdersChart.php

TLDR

This file contains a class called OrdersChart that extends the ChartWidget class. It defines two protected properties heading and sort and two protected methods getType() and getData(). The getType() method returns the string 'line' and the getData() method returns an array of order data.

Classes

OrdersChart

This class extends the ChartWidget class and represents a chart widget for displaying orders per month. It defines two protected properties: heading and sort. The heading property is a nullable string and is set to 'Orders per month'. The sort property is a nullable integer and is set to 1. The class also defines two protected methods: getType() and getData(). The getType() method returns the string 'line', indicating that the chart type is a line chart. The getData() method returns an array of order data and labels for each month.

<?php

namespace App\Filament\Widgets;

use Filament\Widgets\ChartWidget;

class OrdersChart extends ChartWidget
{
    protected static ?string $heading = 'Orders per month';

    protected static ?int $sort = 1;

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

    protected function getData(): array
    {
        return [
            'datasets' => [
                [
                    'label' => 'Orders',
                    'data' => [2433, 3454, 4566, 3300, 5545, 5765, 6787, 8767, 7565, 8576, 9686, 8996],
                    'fill' => 'start',
                ],
            ],
            'labels' => ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
        ];
    }
}