Files
admin-erahn/resources/js/components/Chart/BilanganChart.vue
T
hafifierahman 2090911d55 fix skit2
2022-01-09 18:45:14 +08:00

184 lines
5.1 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">
<content-placeholders v-show="dataready === false">
<content-placeholders-heading :img="true" />
<content-placeholders-text :lines="3" />
</content-placeholders>
<div class="flex items-center justify-between mb-4" v-show="dataready === true">
<div class="flex-shrink-0">
<h3 class="text-base font-normal text-gray-500">Bilangan Orang Bulanan</h3>
</div>
</div>
<div id="chart">
<apexchart v-show="dataready == true" 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,
distributed: true,
style: {
colors: ['#333'],
fontSize: '12px',
fontWeight: 'bold'
},
dropShadow: {
enabled: true,
left: 2,
top: 2,
opacity: 0.5
},
offsetY: -30,
background: {
enabled: true,
foreColor: '#fff',
borderRadius: 2,
padding: 4,
opacity: 0.9,
borderWidth: 1,
borderColor: '#fff'
},
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{
if(isFinite(total))
{
if(total == -100)
{
return 0.00
}else{
return total.toFixed(2)
}
}else{
return 0.00
}
}
},
},
stroke: {
show: true,
width: 2,
colors: ['transparent']
},
legend: {
show: true,
showForSingleSeries: true,
customLegendItems: ['Gadai', 'Tebus','Expected'],
markers: {
fillColors: ['#70a1ff', '#7bed9f','#e74c3c']
}
},
yaxis: {
title: {
text: '(Bilangan Orang)'
}
},
fill: {
opacity: 1,
colors: ['#70a1ff', '#7bed9f']
},
tooltip: {
y: {
formatter: function (val) {
return val + " orang"
}
}
}
},
dataready:false
}),
created() {
this.getData();
},
methods: {
getData(){
this.axios.all([
axios.get(this.$hostname + `/admin/bilangan/gadai`, {
params: {
kodcaw: this.$kodcaw
}
}),
axios.get(this.$hostname + `/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
},
])
this.dataready = true;
}));
}
},
mounted () {
var channel = this.$pusher.subscribe('gadai-notify');
channel.bind('trigger-gadai', ({ cawangan }) => {
if(cawangan = this.$kodcaw)
this.getData()
});
var channel2 = this.$pusher.subscribe('tebus-notify');
channel2.bind('trigger-tebus', ({ cawangan }) => {
if(cawangan = this.$kodcaw)
this.getData()
});
}
}
</script>