Files
admin-erahn/resources/js/components/Chart/KeuntunganChart.vue
T
2021-12-30 00:11:43 +08:00

133 lines
3.1 KiB
Vue

<template>
<div class="mx-auto rounded-lg">
<apexchart
width="500" type="bar"
:options="chartOptions" :series="series">
</apexchart>
</div>
</template>
<script>
const formatter = new Intl.NumberFormat('en-US', {
minimumFractionDigits: 2
});
let self = this;
export default {
name: 'Chart',
props:{
kodcaw: String
},
data: () => ({
series: [
{
name: 'Actual',
data: []
}
],
chartOptions: {
chart: {
id:'keuntungan-bulanan',
height: 350,
type: 'bar'
},
yaxis: {
labels: {
formatter: function (value) {
return 'RM ' + formatter.format(value);
}
},
},
plotOptions: {
bar: {
columnWidth: '60%',
dataLabels: {
position: 'top',
},
}
},
colors: ['#3498db'],
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{
if(isFinite(total))
{
return total.toFixed(2)
}else{
return 0.00
}
}
},
},
legend: {
show: true,
showForSingleSeries: true,
customLegendItems: ['Actual', 'Expected'],
markers: {
fillColors: ['#3498db', '#e74c3c']
}
}
},
}),
created() {
this.getDatakeuntungan()
},
methods: {
getDatakeuntungan () {
this.axios.get('http://localhost:8000/admin/keuntunganBulanan', {
params: {
kodcaw: this.kodcaw
}
}).then(response => {
let keuntungan = [];
keuntungan = response.data
this.$apexcharts.exec('keuntungan-bulanan', 'updateSeries', [{
data: keuntungan
}])
}).catch(error => {
console.log(error)
})
}
},
mounted () {
var channel = this.$pusher.subscribe('keuntungan-notify');
channel.bind('trigger-keuntungan', ({ response }) => {
// console.log(`${response}`);
if(response.cawangan == this.kodcaw)
this.getDatakeuntungan()
});
var channel2 = this.$pusher.subscribe('tebus-notify');
channel2.bind('trigger-tebus', ({ response }) => {
// console.log(`${response}`);
if(response.cawangan == this.kodcaw)
this.getDatakeuntungan()
});
}
}
</script>