Added chart js plugin package and sets static label

This commit is contained in:
dhanabalan
2025-06-27 12:46:29 +05:30
parent fea6573a7a
commit 0fc1852ea2
14 changed files with 6141 additions and 695 deletions

View File

@@ -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)'; }",
// ],
// ],
// ],
// ];
// }
}