Files
admin-erahn/resources/js/components/Chart/BilanganChart.vue
T
2021-12-28 01:23:25 +08:00

147 lines
3.9 KiB
Vue

<template>
<div class="mt-4 bg-white shadow rounded-lg p-4 sm:p-6 xl:p-8 2xl:col-span-1 w-2/3 mx-auto">
<div class="flex items-center justify-between mb-4">
<div class="flex-shrink-0">
<h3 class="text-base font-normal text-gray-500">Bilangan Orang Bulanan</h3>
</div>
</div>
<div id="chart">
<apexchart type="bar" height="350" :options="chartOptions" :series="series"></apexchart>
</div>
</div>
</template>
<script>
export default {
props:{
kodcaw: String
},
data: () => ({
series: [{
name: 'Gadai',
data:[]
}, {
name: 'Tebus',
data:[]
}],
chartOptions: {
chart: {
id:'bilangan-bulanan',
type: 'bar',
height: 350
},
plotOptions: {
bar: {
horizontal: false,
columnWidth: '55%',
endingShape: 'rounded',
dataLabels: {
position: 'top',
},
},
},
dataLabels: {
enabled: true,
style: {
colors: ['#333']
},
offsetY: -30,
formatter: function (val, opt) {
let total = ((val - opt.w.globals.seriesGoals[0][opt.dataPointIndex][0]['value']) / opt.w.globals.seriesGoals[0][opt.dataPointIndex][0]['value']) * 100
if(isNaN(total))
{
return 0.00
}else{
return total.toFixed(2)
}
},
},
stroke: {
show: true,
width: 2,
colors: ['transparent']
},
legend: {
show: true,
showForSingleSeries: true,
customLegendItems: ['Gadai', 'Tebus','Expected'],
markers: {
fillColors: ['#3498db', '#e74c3c','#775DD0']
}
},
yaxis: {
title: {
text: '(Bilangan Orang)'
}
},
fill: {
opacity: 1
},
tooltip: {
y: {
formatter: function (val) {
return val + " orang"
}
}
}
},
}),
created() {
this.getData();
},
methods: {
getData(){
this.axios.all([
axios.get(`http://localhost:8000/admin/bilangan/gadai`, {
params: {
kodcaw: this.kodcaw
}
}),
axios.get(`http://localhost:8000/admin/bilangan/tebus`, {
params: {
kodcaw: this.kodcaw
}
})
])
.then(this.axios.spread((datagadai, datatebus) => {
this.$apexcharts.exec('bilangan-bulanan', 'updateSeries', [
{
name: 'Gadai',
data: datagadai.data
},
{
name: 'Tebus',
data: datatebus.data
},
])
}));
}
},
mounted () {
var channel = this.$pusher.subscribe('gadai-notify');
channel.bind('trigger-gadai', ({ response }) => {
if(response.cawangan = this.kodcaw)
this.getData()
});
var channel2 = this.$pusher.subscribe('tebus-notify');
channel2.bind('trigger-tebus', ({ response }) => {
if(response.cawangan = this.kodcaw)
this.getData()
});
}
}
</script>