imranhsayed / laravel-charts

:bar_chart: Create a chart in Laravel using Chart.js and AJAX
39 stars 36 forks source link

Year #11

Open alexizzz0 opened 3 years ago

alexizzz0 commented 3 years ago

How would you resolve the issue of having months overlap in years. For Example: Jan 2020 and Jan 2021 If the dataset is large enough then it will overlap and the chart will add those months together.

I was thinking there is sorting when you write the sql query but what then the distinguishing factor becomes the year and not the month name.

I'm still a noob but this tutorial was so great i thought you would be able to answer this faster than i could solve it myself.

AselGunaratne commented 3 years ago

Im a bit of a noob myself but I used string concat for this and it worked for me. You can try the following code to replace the foreach loop

$date = new \DateTime($unformatted_date); $month_no = strval($date->format('m')); $year_no = strval($date->format('y')); $month_year_no=$month_no.$year_no; $month_name = $date->format('M'); $year_name = $date->format('Y'); $month_year_name=$month_name.(" ").$year_name; $month_array[$month_year_no] = $month_year_name;

hope this answers your requirement :)