@lacoder based on your scenario, add this block of code right before the $data = $query->get(); line
// Check if $timeFrame is set and greater than 1
if ($this->timeFrame && $this->timeFrame > 1) {
// Calculate the number of rows to include in each group
$rowsPerGroup = $this->timeFrame / 3; // Assuming each row represents 3 minutes
// Calculate the group number for each row based on the time
$query->selectRaw('FLOOR(MINUTE(time) / (:rowsPerGroup * 3)) AS group_number', ['rowsPerGroup' => $rowsPerGroup]);
// Group the rows based on the calculated group number
$query->groupBy('group_number');
// Select the sum of column values for each group
// Replace column_name with the name of the column for which you want to calculate the sum
$query->selectRaw('SUM(column_name) AS sum_of_column');
}