Files
real-estate-app/app/Support/ChartJsFormatter.php
Kurtis Holsapple ee37c6de85
Some checks failed
linter / quality (push) Failing after 3m48s
tests / ci (push) Failing after 4m13s
initial commit
2025-07-12 15:01:28 -07:00

36 lines
1.0 KiB
PHP

<?php
namespace App\Support;
use Illuminate\Support\Collection;
class ChartJsFormatter
{
public static function barChart(array|Collection $labels, array $datasets): array
{
return [
'type' => 'bar',
'data' => [
'labels' => $labels,
'datasets' => array_map(function ($dataset) {
return [
'label' => $dataset['label'],
'data' => $dataset['data'],
'backgroundColor' => $dataset['backgroundColor'] ?? 'rgba(75, 192, 192, 0.6)',
'borderColor' => $dataset['borderColor'] ?? 'rgba(75, 192, 192, 1)',
'borderWidth' => $dataset['borderWidth'] ?? 1,
];
}, $datasets),
],
'options' => [
'responsive' => true,
'scales' => [
'y' => [
'beginAtZero' => true,
],
],
],
];
}
}