Skip to content

Instantly share code, notes, and snippets.

@faridfr
Last active October 11, 2022 16:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save faridfr/eb9e000efe417973b6a88b263c1e76de to your computer and use it in GitHub Desktop.
Save faridfr/eb9e000efe417973b6a88b263c1e76de to your computer and use it in GitHub Desktop.
Hourly Chart Back End Code In Laravel
<?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