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/a4f40bba52913219408397360c88bdd9 to your computer and use it in GitHub Desktop.
Save faridfr/a4f40bba52913219408397360c88bdd9 to your computer and use it in GitHub Desktop.
Monthly Chart Back End Laravel With Jalali Dates
<?php
$results['x'] = [];
$results['y'] = [];
$results['xy'] = [];
for($i=30;$i>=0;$i--)
{
$x = date('Y-m-d',strtotime('-'.$i.' days'));
$y = Order::where('created_at','like','%'.$x.'%')
->where('store_id',$storeId)
->count('id');
// You can use whereDate('created_at','=',$x)
// Calculate data here and change the value of X and Y ...
$jalali = jdate($x)->format('Y-m-d');
array_push($results['y'],$y);
array_push($results['xy'],["x"=>$jalali,"y"=>$y]);
array_push($results['x'],$jalali);
}
return [
'xAxis' => $results['x'],
'yAxis' => $results['y'],
'xy' => $results['xy'],
];
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment