update
parent
863253c45b
commit
5e8dd24894
|
|
@ -16,7 +16,77 @@ use SoftDeletes;
|
|||
|
||||
protected $guarded = [];
|
||||
|
||||
function dataset() {
|
||||
function dataset() {
|
||||
return $this->belongsTo('App\Models\Dataset','dataset_id');
|
||||
}
|
||||
|
||||
public static function dataChart($modelClass,$datasetId,$templateId){
|
||||
|
||||
$datasets = \App\Models\Dataset::where('template_id', $templateId)
|
||||
->orderBy('tahun', 'asc')
|
||||
->get()
|
||||
->map(function ($dataset) use ($modelClass) {
|
||||
$dataset->items = (new $modelClass)->where('dataset_id', $dataset->id)->get();
|
||||
return $dataset;
|
||||
});
|
||||
$years = $datasets->pluck('tahun')->toArray();
|
||||
$model = self::with('dataset')->whereHas('dataset',function($query) use ($years){
|
||||
$query->whereIn('tahun',$years);
|
||||
})->where('dataset_id',$datasetId)->get();
|
||||
|
||||
$result = [];
|
||||
foreach ($model as $row) {
|
||||
$lokasi = $row->lokasi ?? 'Unknown';
|
||||
|
||||
if (!isset($result[$lokasi])) {
|
||||
$result[$lokasi] = [
|
||||
'lokasi' => [],
|
||||
'tidak_sekolah' => [],
|
||||
'sd' => [],
|
||||
'sltp' => [],
|
||||
'slta' => [],
|
||||
'pt' => [],
|
||||
];
|
||||
}
|
||||
|
||||
$result[$lokasi]['lokasi'][] = (float) $row->lokasi;
|
||||
$result[$lokasi]['tidak_sekolah'][] = (float) $row->tidak_sekolah_l+(float) $row->tidak_sekolah_p;
|
||||
$result[$lokasi]['sd'][] = (float) $row->sd_p+(float) $row->sd_l;
|
||||
$result[$lokasi]['sltp'][] = (float) $row->sltp_p+(float) $row->sltp_l;
|
||||
$result[$lokasi]['slta'][] = (float) $row->slta_smk_p+(float) $row->slta_smk_l;
|
||||
$result[$lokasi]['pt'][] = (float) $row->pt_p+(float) $row->pt_l;
|
||||
}
|
||||
|
||||
return [
|
||||
'title' => '',
|
||||
'years' => $years,
|
||||
'yTitle' => 'Jumlah',
|
||||
'yOpposite' => '',
|
||||
'series' => collect($result)->flatMap(function ($item, $lokasi) {
|
||||
return [
|
||||
[
|
||||
'name' => "Tidak Sekolah - {$lokasi}",
|
||||
'type' => 'column',
|
||||
'data' => $item['tidak_sekolah']
|
||||
],[
|
||||
'name' => "SD - {$lokasi}",
|
||||
'type' => 'column',
|
||||
'data' => $item['sd']
|
||||
],[
|
||||
'name' => "SMP - {$lokasi}",
|
||||
'type' => 'column',
|
||||
'data' => $item['sltp']
|
||||
],[
|
||||
'name' => "SMA/SMK - {$lokasi}",
|
||||
'type' => 'column',
|
||||
'data' => $item['slta']
|
||||
],[
|
||||
'name' => "Perguruan Tinggi - {$lokasi}",
|
||||
'type' => 'column',
|
||||
'data' => $item['pt']
|
||||
],
|
||||
];
|
||||
})->values()
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,28 +34,26 @@
|
|||
<script src="{{asset('assets/libs/jsvectormap/maps/world-merc.js')}}"></script>
|
||||
<script src="{{asset('assets/libs/jsvectormap/maps/world.js')}}"></script>
|
||||
<script>
|
||||
var base_url = '{{ url("dashboard/api/chart/".encode_id($template->MsTemplateId)."/".encode_id($instansi_id)) }}';
|
||||
fetch(base_url)
|
||||
.then(res => res.json())
|
||||
.then(res => {
|
||||
const options = {
|
||||
chart: { type: 'line', height: 480 },
|
||||
title: { text: res.title, align: 'center' },
|
||||
xaxis: { categories: res.years, title: { text: 'Tahun' } },
|
||||
yaxis: [
|
||||
{ title: { text: res.yTitle } },
|
||||
{ opposite: true, min: 0, max: 100, title: { text: res.yOpposite } }
|
||||
],
|
||||
tooltip: { shared: true, intersect: false },
|
||||
stroke: { width: [0,3] },
|
||||
plotOptions: { bar: { columnWidth: '45%' } },
|
||||
legend: { position: 'bottom' },
|
||||
series: res.series
|
||||
};
|
||||
|
||||
new ApexCharts(document.querySelector("#chart"), options).render();
|
||||
});
|
||||
|
||||
var base_url = '{{ url("dashboard/api/chart/".encode_id($template->MsTemplateId)."/".encode_id($instansi_id)) }}';
|
||||
fetch(base_url).then(res => res.json()).then(
|
||||
res => {
|
||||
const options = {
|
||||
chart: {
|
||||
type: 'line',
|
||||
height: 480
|
||||
},
|
||||
title: { text: res.title, align: 'center' },
|
||||
xaxis: { categories: res.years, title: { text: 'Tahun' } },
|
||||
yaxis: [
|
||||
|
||||
{ opposite: false, min: 0, title: { text: res.yOpposite } }
|
||||
],
|
||||
tooltip: { shared: true, intersect: false },
|
||||
stroke: { width: [0,1] },
|
||||
plotOptions: { bar: { columnWidth: '45%' } },
|
||||
legend: { position: 'left' },
|
||||
series: res.series
|
||||
}; new ApexCharts(document.querySelector("#chart"), options).render(); });
|
||||
</script>
|
||||
|
||||
@endsection
|
||||
Loading…
Reference in New Issue