Added chart js plugin package and sets static label
This commit is contained in:
@@ -6,6 +6,7 @@ use App\Models\GuardPatrolEntry;
|
||||
use Carbon\Carbon;
|
||||
use DB;
|
||||
use Filament\Widgets\ChartWidget;
|
||||
use Filament\Support\RawJs;
|
||||
|
||||
class GuardPatrolDayChart extends ChartWidget
|
||||
{
|
||||
@@ -42,7 +43,6 @@ class GuardPatrolDayChart extends ChartWidget
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
$uniqueGuardNames = GuardPatrolEntry::join('guard_names', 'guard_patrol_entries.guard_name_id', '=', 'guard_names.id')
|
||||
->where('guard_patrol_entries.plant_id', $selectedPlant)
|
||||
->select('guard_names.id', 'guard_names.name')
|
||||
@@ -99,6 +99,10 @@ class GuardPatrolDayChart extends ChartWidget
|
||||
}
|
||||
}
|
||||
|
||||
$chartData = array_map(function ($value) {
|
||||
return ($value == 0 || is_null($value)) ? null : $value;
|
||||
}, $chartData);
|
||||
|
||||
return [
|
||||
'labels' => array_values($uniqueGuardNames),
|
||||
'datasets' => [
|
||||
@@ -143,27 +147,21 @@ class GuardPatrolDayChart extends ChartWidget
|
||||
],
|
||||
],
|
||||
],
|
||||
'plugins' => [
|
||||
'datalabels' => [
|
||||
'anchor' => 'start',
|
||||
'align' => 'start',
|
||||
'offset' => 4,
|
||||
'color' => '#000',
|
||||
'font' => [
|
||||
'weight' => 'bold',
|
||||
],
|
||||
'formatter' => RawJs::make('function(value) {
|
||||
return value;
|
||||
}'),
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
// protected function getOptions(): array
|
||||
// {
|
||||
// return [
|
||||
// 'scales' => [
|
||||
// 'y' => [
|
||||
// 'beginAtZero' => true, // Start Y-axis from 0
|
||||
// 'ticks' => [
|
||||
// 'stepSize' => 5,
|
||||
// ],
|
||||
// ],
|
||||
// ],
|
||||
// 'plugins' => [
|
||||
// 'tooltip' => [
|
||||
// 'callbacks' => [
|
||||
// 'label' => "function(context) { return context.parsed.y + ' (min)'; }",
|
||||
// ],
|
||||
// ],
|
||||
// ],
|
||||
// ];
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user