         return expenses
                .filter(exp => exp.amount > 0)
                .reduce((sum, exp) => sum + exp.amount, 0);
        }

        function calculateExpenses(expenses) {
            return expenses
                .filter(exp => exp.amount < 0)
                .reduce((sum, exp) => sum + Math.abs(exp.amount), 0);
        }

        function updateChartAndLegend() {
            const monthExpenses = getMonthExpenses(allExpenses);
            const chartBox = document.querySelector('.chart