Files
nuhodds_fi4/app/Filament/Widgets/Data/HelperMoveingAverage.php
T
2026-05-23 17:14:58 +02:00

27 lines
699 B
PHP

<?php
namespace App\Filament\Widgets\Data;
class HelperMoveingAverage
{
public static function get(&$data)
{
$arr = $data['datasets'][0]['data'];
$data['labels'] = array_slice($data['labels'], 2);
$new = [];
$last = count($arr);
foreach ($arr as $key => $value) {
if ($key == 1 && $last > 2) {
$new[] = round(($arr[0] + $value + $arr[2]) / 3, 1);
} elseif ($key > 1 && $key < $last - 1) {
$new[] = round(($arr[$key - 1] + $value + $arr[$key + 1]) / 3, 1);
}
}
$data['datasets'][0]['borderColor'] = '#00a63e';
$data['datasets'][0]['data'] = $new;
}
}