    }

        function updateLegend(categoryData) {
            const legendContainer = document.getElementById('customLegend');
            legendContainer.innerHTML = '';
            const monthExpenses = getMonthExpenses(allExpenses);
            const currentMonthCategories = [...new Set(monthExpenses
                .filter(exp => exp.amount < 0)
                .map(exp => exp.category))];
            const categoryMap = new Map(categoryData.map(cat => [cat.category, cat]));
            
            