<template>
    <div>
        <piechart
        :height="300"
        :width="200"
        :pieData="pieData"
        :update="update_chart"
        :key="key"
        />
    </div>
</template>

<script>
import piechart from '../PieChart';
import moment from "moment";
export default {
    name: 'MyAppVuePieRevenueChart',
    components:{
        piechart,moment
    },

    data() {
        return {
            pieData:{'monney':0,'account':0,'all':0},
            key:0,
            update_chart:null,
            polling: null,
        };
    },

    mounted() {
        
    },

    methods: {
        GetGrap(month){
         this.month = month;
          //this.$Progress.start();
            this.$axios.get("/sanctum/csrf-cookie").then((response) => {
              axios
                .post(`/api/dashboard/dash_cap`,{
                  month:month
                }).then((response) => {
                    
                  this.pieData.monney = response.data.asset_monney;
                  this.pieData.account = response.data.asset_monney_acc_kip;
                  this.pieData.all = this.pieData.monney+this.pieData.account;
                  //this.pieData = {'monney':response.data.asset_monney,'account':response.data.asset_monney_acc_kip,'all':response.data.asset_monney+response.data.asset_monney_acc_kip}
                  //console.log(this.update_chart );
                  this.polling = setInterval(() => {
                
                      this.key++;
                      this.update_chart = Math.floor(Math.random() * 100);

                    clearInterval(this.polling);
                  }, 1500);
                  
                 // this.$Progress.finish();
                })
                .catch((error) => {
                  this.$notify( { group: "error", title: "ບໍ່ສຳເລັດ!", text: "ຜິດຜາດ: " + error.message, }, 4000 );
                  console.error(error);
                 // this.$Progress.fail();
                });
            });
        },
    },
    created(){

        let get_month = new Date();
        let month = get_month.getMonth()+1;
     
      this.GetGrap(month);
    }
};
</script>

<style lang="scss" scoped>

</style>