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