Last active
October 11, 2022 16:48
-
-
Save faridfr/eb9e000efe417973b6a88b263c1e76de to your computer and use it in GitHub Desktop.
Hourly Chart Back End Code In Laravel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$posts = \DB::select(" | |
Select date_format(created_at, '%H') as hour, count(id) as count | |
From posts WHERE deleted_at IS NULL | |
Group by date_format(created_at, '%H') | |
"); | |
$xAxis = array(); | |
$yAxis = array(); | |
$xy = array(); | |
foreach($posts as $post) | |
{ | |
array_push($xAxis,$post->hour); | |
array_push($yAxis,(int)$post->count); | |
array_push($xy,[ "x" => $post->hour , "y" => (int)$post->count ]); | |
} | |
return [ | |
'xAxis' => $xAxis, | |
'yAxis' => $yAxis, | |
'xy' => $xy, | |
]; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment