    const labels = Object.keys(dataByYear[Object.keys(dataByYear)[0]]);
    const datasets = [];

    Object.keys(dataByYear).forEach(year => {
        datasets.push({
            label: `Tahun ${year}`,
            backgroundColor: getRandomColor(),
            borderColor: getRandomColor(),
            borderWidth: 1,
            data: Object.values(dataByYear[year])
        });
    });

    var ctx = document.getElementById("myBarChart").getContext("2d");
    var myBarChart = new Chart(ctx, {
        type: 'bar',
        data: {
            labels: labels,
            datasets: datasets
        },
        options: {
            scales: {
                y: {
                    beginAtZero: true
                }
            }
        }
    });

    function getRandomColor() {
        var letters = '0123456789ABCDEF';
        var color = '#';
        for (var i = 0; i < 6; i++) {
            color += letters[Math.floor(Math.random() * 16)];
        }
        return color;
    }