I am creating a historical Graph using ChartJS. And I need to Filter the array Values 30 Days Ago
I have an array with the values below:
[0] => Array
(
[datetime] => 4/1/2019 4:00:00 PM - 5:00:00 PM
[value_raw] => 100
)
[1] => Array
(
[datetime] => 4/1/2019 3:00:00 PM - 4:00:00 PM
[value_raw] => 101
)
[2] => Array
(
[datetime] => 4/1/2019 2:00:00 PM - 3:00:00 PM
[value_raw] => 99
)
The Array has large content and contains up to more than 5 months value of every hour every day
This is my current php code as of now for the labels in the ChartJS Script:
LABELS CODE:
labels: [
<?php
for($i=0; $i<=30; $i++)
{
$label = date('n/d/Y', strtotime('-'.$i.' days',strtotime(date('n/d/Y'))));
echo '"'.$label.'",';
}
?>
],
Result:
4/01/2019, 3/31/2019, 3/30/2019, 3/29/2019
However I'am having hard time on how am I going to get the equivalent MAX Value per day in parallel to/matching my Labels Code.
DATA CODE:
data: [
<?php
foreach ($my_array as $key => $value) {
for($i=0; $i<=30; $i++)
{
$label = date('n/d/Y', strtotime('-'.$i.' days',strtotime(date('n/d/Y'))));
if ($label == changeFormat($value[datetime]))
{
echo $value['value_raw'].',';
}
}
}
?>
],
My Expected Result should be the MAX Value of the Day of the Past 30 Days :
Example:
DATE VALUE
4/01/2019 99
3/31/2019 101
3/30/2019 100
3/29/2019 95
Result:
99, 101, 100, 95