I try to make a Chart.js chart in Laravel/PHP with the plugin Fxcosta. So I am quite new to this community, as well as the programming languages. I try to make a dynamic chart with all the days of the actual month. (In November = 30 days). With this task I created a function (calcDaysOfActualMonth) which returns an array with all the days of the actual month. So my current problem is, that I want to start my chart with day 1 and not 0. So when I change the loop index to 1 I can't pass the array $labelsArr to my chart because it's not starting with 0.
// CHART LAST MONTH
$labelsArr = $this->calcDaysOfActualMonth();
$chartjs = app()
->chartjs
->name('lineChartTest')
->type('line')
->size(['width' => 400, 'height' => 200])
->labels($labelsArr)
->datasets([
[
"label" => "Actual Month",
'backgroundColor' => "rgba(38, 185, 154, 0.31)",
'borderColor' => "rgba(38, 185, 154, 0.7)",
"pointBorderColor" => "rgba(38, 185, 154, 0.7)",
"pointBackgroundColor" => "rgba(38, 185, 154, 0.7)",
"pointHoverBackgroundColor" => "#fff",
"pointHoverBorderColor" => "rgba(220,220,220,1)",
'data' => [65, 59, 55, 12, 33, 65, 59, 80, 81, 56,65, 12, 55, 12, 33, 55, 59, 80, 81, 56,65, 59, 80, 81, 56,65, 59, 80, 81, 56],
]
])
->options([]);
My function trying to create an array indexing with 1, starting with 0 is working, starting with 1 is not working:
private function calcDaysOfActualMonth(){
$days = date("t");
$daysArr = [];
for($i=0; $i<$days; $i++){
$daysArr[$i] = $i;
}
return $daysArr;
}
My Chart is this one, staring currently with 0: My Chart of actual month
Excuse me sincerly when it's a real trivial problem. And I hope I gave enough information! Thank you very much in advance.