From 6449a92a322372eb5952533fc541fcb59b8ab80c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Anne?= Date: Mon, 22 Jan 2024 17:55:42 +0100 Subject: [PATCH] Fix printer counters history chart (#16386) --- src/PrinterLog.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/PrinterLog.php b/src/PrinterLog.php index ab56b131419..7323a4fe924 100644 --- a/src/PrinterLog.php +++ b/src/PrinterLog.php @@ -180,15 +180,22 @@ public function showMetrics(Printer $printer) $labels[] = $fmt->format($date); unset($metrics['id'], $metrics['date'], $metrics['printers_id']); + // Keep values if at least 1 label is greater than 0 + $valuesum = array_sum($metrics); foreach ($metrics as $key => $value) { $label = $this->getLabelFor($key); - if ($label && $value > 0) { + if ($label && $valuesum > 0) { $series[$key]['name'] = $label; $series[$key]['data'][] = $value; } } } - + // If the metric has a value of 0 for all dates, remove it from the data set + foreach ($series as $key => $value) { + if (array_sum($value['data']) == 0) { + unset($series[$key]); + } + } $bar_conf = [ 'data' => [ 'labels' => $labels,