initial commit
This commit is contained in:
35
app/Support/ChartJsFormatter.php
Normal file
35
app/Support/ChartJsFormatter.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?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,
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user