adjusted label position of the x axis bar in hourly production chart
This commit is contained in:
@@ -105,21 +105,40 @@ class ItemOverview extends ChartWidget
|
||||
$data[0] ?? 0,
|
||||
];
|
||||
}
|
||||
// else
|
||||
// {
|
||||
// $allHours = array_fill(0, 24, 0);
|
||||
// $data = array_replace($allHours, $query);
|
||||
|
||||
// $shiftedKeys = array_merge(range(8, 23), range(0, 7));
|
||||
// $orderedData = array_map(fn($hour) => $data[$hour], $shiftedKeys);
|
||||
|
||||
// $labels = array_map(fn ($hour) => date("g A", strtotime("$hour:00")), $shiftedKeys);
|
||||
// }
|
||||
|
||||
else
|
||||
{
|
||||
$allHours = array_fill(0, 24, 0);
|
||||
$data = array_replace($allHours, $query);
|
||||
|
||||
$shiftedKeys = array_merge(range(8, 23), range(0, 7));
|
||||
$orderedData = array_map(fn($hour) => $data[$hour], $shiftedKeys);
|
||||
$shiftedData = [];
|
||||
foreach ($data as $hour => $count) {
|
||||
$nextHour = ($hour + 1) % 24;
|
||||
$shiftedData[$nextHour] = $count;
|
||||
}
|
||||
$shiftedKeys = array_merge(range(9, 23), range(0, 8));
|
||||
$orderedData = array_map(fn($hour) => $shiftedData[$hour] ?? 0, $shiftedKeys);
|
||||
|
||||
$labels = array_map(fn ($hour) => date("g A", strtotime("$hour:00")), $shiftedKeys);
|
||||
$labels = array_map(function($hour) {
|
||||
$prevHour = ($hour - 1 + 24) % 24;
|
||||
return sprintf("%s",
|
||||
date("g A", strtotime("$hour:00")),
|
||||
date("g", strtotime("$prevHour:00")),
|
||||
date("g A", strtotime("$hour:00"))
|
||||
);
|
||||
}, $shiftedKeys);
|
||||
}
|
||||
|
||||
// $orderedData = array_map(function ($value) {
|
||||
// return ($value == 0 || is_null($value)) ? null : $value;
|
||||
// }, $orderedData);
|
||||
|
||||
return [
|
||||
'datasets' => [
|
||||
[
|
||||
|
||||
Reference in New Issue
Block a user