Closed stephen-morlex closed 2 years ago
Can you please reformat the code:
$students_area = Student::where('status_id', 6)->get();
$areaChartModel = $students_area
->reduce(
function ($areaChartModel, $data) use ($students_area) {
$index = $students_area->search($data);
return $areaChartModel->addPoint($index, $data->updated_at->addMonth(), ['id' => $data->id]);
},
LivewireCharts::areaChartModel()
->setTitle('Students Graduated by Month')
->setAnimated($this->firstRun)
->setColor('#3B82F6')
->withOnPointClickEvent('onAreaPointClick')
->setDataLabelsEnabled($this->showDataLabels)
->sparklined()
->setXAxisVisible($this->visible)
->setYAxisVisible($this->visible)
->withGrid()
);
<div class="h-80">
<livewire:livewire-area-chart key="{{ $areaChartModel->reactiveKey() }}"
:area-chart-model="$areaChartModel" />
</div>
$students_area = Student::where('status_id', 6)->get();
$areaChartModel = $students_area
->reduce(
function ($areaChartModel, $data) use ($students_area) {
$index = $students_area->search($data);
return $areaChartModel->addPoint($index, $data->updated_at->addMonth(), ['id' => $data->id]);
},
LivewireCharts::areaChartModel()
->setTitle('Students Graduated by Month')
->setAnimated($this->firstRun)
->setColor('#3B82F6')
->withOnPointClickEvent('onAreaPointClick')
->setDataLabelsEnabled($this->showDataLabels)
->sparklined()
->setXAxisVisible($this->visible)
->setYAxisVisible($this->visible)
->withGrid()
);
<div class="h-80">
<livewire:livewire-area-chart key="{{ $areaChartModel->reactiveKey() }}"
:area-chart-model="$areaChartModel" />
</div>
I think it would be clearer if you add the addPoint-methods in a foreach-loop.
I'm stuck here i tried many possible ways, but i can't seem to get the query right and display the data on the chart.
$students_area = Student::where('status_id', 6)->latest()->get()
->groupBy(function ($val) {
return Carbon::parse($val->updated_at)->format('M Y');
});
$lineChartModel = $students_area
->reduce(
function ($lineChartModel, $data) use ($students_area) {
$index = $students_area->search($data);
$value = $data->count('id');
return $lineChartModel->addPoint($index, $value, $index);
},
LivewireCharts::lineChartModel()
->setTitle('Total Number of Students Graduated by Month of the Year')
->setSmoothCurve()
->setYAxisVisible(true)
->withGrid()
->withDataLabels()
->setDataLabelsEnabled(true)
->setStrokeWidth(5)
->setColors(['#fa678f'])
);
I want to display chart of the student according to the students status and group by updated_at column month. Below is my current code thanks.
$students_area = Student::where('status_id', 6)->get(); $areaChartModel = $students_area ->reduce( function ($areaChartModel, $data) use ($students_area) { $index = $students_area->search($data); return $areaChartModel->addPoint($index, $data->updated_at, ['id' => $data->id]); }, LivewireCharts::areaChartModel() ->setTitle('Students Graduated by Month') ->setAnimated($this->firstRun) ->setColor('#3B82F6') ->withOnPointClickEvent('onAreaPointClick') ->setDataLabelsEnabled($this->showDataLabels) ->sparklined() ->setXAxisVisible($this->visible) ->setYAxisVisible($this->visible) ->withGrid() );