FilamentF
Filament7mo ago
morty

Can't get scatter chart to work?

Does anyone have an example of getting the scatter chart to work in a widget? Mine doesn't. This is how I've formatted my data as an example:

    protected function getData(): array
    {
        return [
            'datasets' => [
                [
                    'label' => 'Cereals',
                    'data' => array_map(fn () => rand(5, 100), range(1, 12)),
                    'backgroundColor' => 'rgb('.Color::Blue[50].')',
                    'borderColor' => 'rgb('.Color::Blue[500].')',
                ],
                [
                    'label' => 'RR Soy',
                    'data' => array_map(fn () => rand(5, 100), range(1, 12)),
                    'backgroundColor' => 'rgb('.Color::Orange[50].')',
                    'borderColor' => 'rgb('.Color::Orange[500].')',
                ],
                [
                    'label' => 'Soy',
                    'data' => array_map(fn () => rand(5, 100), range(1, 12)),
                    'backgroundColor' => 'rgb('.Color::Purple[50].')',
                    'borderColor' => 'rgb('.Color::Purple[500].')',
                ],
                [
                    'label' => 'Wheat',
                    'data' => array_map(fn () => rand(5, 100), range(1, 12)),
                    'backgroundColor' => 'rgb('.Color::Green[50].')',
                    'borderColor' => 'rgb('.Color::Green[500].')',
                ],
            ],
            'labels' => array_map(fn ($month) => Carbon::create(null, $month)->format('F'), range(1, 12)),
        ];
    }


This exact format works for a bar chart.
Solution
nvm, I'm using it wrong.

Unlike the line chart where data can be supplied in two different formats, the scatter chart only accepts data in a point format
Was this page helpful?