
let incomeByBarberCtx = document.getElementById('incomeByBarberChart').getContext('2d');

let incomeByBarberLabels = incomeByBarber.map(incomeByBarber => incomeByBarber.biography.full_name);
let incomeByBarberData = incomeByBarber.map(incomeByBarber => incomeByBarber.transactions_sum_total);

let incomeByBarberBackgroundColors = incomeByBarberData.map(() => getRandomColor());
let incomeByBarberBorderColors = incomeByBarberBackgroundColors.map(color => color.replace('0.2', '1'));

let incomeByBarberChart = new Chart(incomeByBarberCtx, {
    type: 'pie',
    data: {
        labels: incomeByBarberLabels,
        datasets: [{
            label: 'Pendapatan',
            data: incomeByBarberData,
            backgroundColor: incomeByBarberBackgroundColors,
            borderColor: incomeByBarberBorderColors,
            borderWidth: 1
        }]
    },
    options: {
        responsive: true,
        plugins: {
            legend: {
                position: 'top',
            },
            tooltip: {
                callbacks: {
                    label: function (tooltipItem) {
                        let rupiahFormat = new Intl.NumberFormat('id-ID', {
                            style: 'currency',
                            currency: 'IDR',
                            maximumFractionDigits: 0,
                            useGrouping: true
                        }).format(tooltipItem.raw);

                        return tooltipItem.label + ': ' + rupiahFormat.replace('Rp ', 'Rp').replace(/\s/g, '');
                    }
                }
            }
        }
    }
});
