Cost to Sell House Calculator

Cost to Sell House Calculator & Guide | Your Trusted Financial Tool :root { –primary-color: #004a99; –success-color: #28a745; –background-color: #f8f9fa; –text-color: #333; –border-color: #ddd; –card-background: #fff; –shadow: 0 2px 5px rgba(0,0,0,0.1); } body { font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; background-color: var(–background-color); color: var(–text-color); line-height: 1.6; margin: 0; padding: 0; } .container { max-width: 1000px; margin: 20px auto; padding: 20px; background-color: var(–card-background); border-radius: 8px; box-shadow: var(–shadow); } header { background-color: var(–primary-color); color: white; padding: 20px 0; text-align: center; margin-bottom: 20px; border-radius: 8px 8px 0 0; } header h1 { margin: 0; font-size: 2.5em; } .calculator-section { margin-bottom: 40px; padding: 30px; border: 1px solid var(–border-color); border-radius: 8px; background-color: var(–card-background); box-shadow: var(–shadow); } .calculator-section h2 { color: var(–primary-color); text-align: center; margin-top: 0; margin-bottom: 25px; } .loan-calc-container { display: grid; grid-template-columns: 1fr; gap: 20px; } .input-group { display: flex; flex-direction: column; gap: 8px; } .input-group label { font-weight: bold; color: var(–primary-color); } .input-group input[type="number"], .input-group input[type="text"], .input-group select { padding: 12px; border: 1px solid var(–border-color); border-radius: 4px; font-size: 1em; box-sizing: border-box; } .input-group input[type="number"]:focus, .input-group input[type="text"]:focus, .input-group select:focus { outline: none; border-color: var(–primary-color); box-shadow: 0 0 0 2px rgba(0, 74, 153, 0.2); } .input-group .helper-text { font-size: 0.85em; color: #666; margin-top: 4px; } .error-message { color: red; font-size: 0.85em; margin-top: 4px; min-height: 1.2em; /* Prevent layout shift */ } .button-group { display: flex; justify-content: center; gap: 15px; margin-top: 25px; flex-wrap: wrap; } button { padding: 12px 25px; border: none; border-radius: 5px; cursor: pointer; font-size: 1em; font-weight: bold; transition: background-color 0.3s ease; } .btn-calculate { background-color: var(–primary-color); color: white; } .btn-calculate:hover { background-color: #003366; } .btn-reset { background-color: #6c757d; color: white; } .btn-reset:hover { background-color: #5a6268; } .btn-copy { background-color: #ffc107; color: #212529; } .btn-copy:hover { background-color: #e0a800; } #results { margin-top: 30px; padding: 25px; border: 1px solid var(–border-color); border-radius: 8px; background-color: var(–card-background); box-shadow: var(–shadow); text-align: center; } #results h3 { color: var(–primary-color); margin-top: 0; margin-bottom: 20px; } .primary-result { font-size: 2.2em; font-weight: bold; color: var(–success-color); margin-bottom: 15px; padding: 10px; background-color: #e9f7ef; border-radius: 5px; display: inline-block; } .intermediate-results div { margin-bottom: 10px; font-size: 1.1em; } .intermediate-results span { font-weight: bold; color: var(–primary-color); } .formula-explanation { font-size: 0.9em; color: #555; margin-top: 15px; padding-top: 15px; border-top: 1px dashed var(–border-color); } table { width: 100%; border-collapse: collapse; margin-top: 20px; box-shadow: var(–shadow); } th, td { padding: 12px 15px; text-align: left; border: 1px solid var(–border-color); } thead { background-color: var(–primary-color); color: white; } tbody tr:nth-child(even) { background-color: #f2f2f2; } caption { font-size: 1.1em; font-weight: bold; color: var(–primary-color); margin-bottom: 10px; text-align: left; } canvas { display: block; margin: 20px auto; max-width: 100%; border: 1px solid var(–border-color); border-radius: 4px; } .chart-legend { text-align: center; margin-top: 10px; font-size: 0.9em; color: #555; } .chart-legend span { display: inline-block; margin: 0 10px; } .chart-legend .color-box { display: inline-block; width: 12px; height: 12px; margin-right: 5px; vertical-align: middle; border-radius: 3px; } .legend-commission { background-color: #007bff; } .legend-other { background-color: #6c757d; } .article-section { margin-top: 40px; padding: 30px; border: 1px solid var(–border-color); border-radius: 8px; background-color: var(–card-background); box-shadow: var(–shadow); } .article-section h2, .article-section h3 { color: var(–primary-color); margin-bottom: 15px; } .article-section h2 { border-bottom: 2px solid var(–primary-color); padding-bottom: 8px; } .article-section p, .article-section ul, .article-section ol { margin-bottom: 15px; } .article-section li { margin-bottom: 8px; } .faq-item { margin-bottom: 15px; border-bottom: 1px dashed var(–border-color); padding-bottom: 10px; } .faq-item:last-child { border-bottom: none; } .faq-question { font-weight: bold; color: var(–primary-color); cursor: pointer; display: block; margin-bottom: 5px; } .faq-answer { display: none; font-size: 0.95em; color: #555; } .internal-links-section ul { list-style: none; padding: 0; } .internal-links-section li { margin-bottom: 12px; } .internal-links-section a { color: var(–primary-color); text-decoration: none; font-weight: bold; } .internal-links-section a:hover { text-decoration: underline; } .internal-links-section p { font-size: 0.9em; color: #555; margin-top: 5px; } .highlight { background-color: #fff3cd; padding: 2px 5px; border-radius: 3px; } @media (min-width: 768px) { .loan-calc-container { grid-template-columns: repeat(2, 1fr); } .button-group { justify-content: flex-end; } }

Cost to Sell House Calculator

Estimate your net proceeds from selling your home.

Calculate Your Selling Costs

The price you expect to sell your home for.
Typically 4-6% of the sale price.
Includes title fees, escrow, transfer taxes, etc. (2-4% is common).
Costs for necessary repairs or upgrades.
Staging, cleaning, moving expenses, etc.
The outstanding amount on your current mortgage.

Your Estimated Selling Costs Summary

$0.00
Agent Commission: $0.00
Closing Costs: $0.00
Total Selling Expenses: $0.00
Formula: Net Proceeds = Sale Price – (Sale Price * Agent Commission Rate) – (Sale Price * Closing Costs Rate) – Repair Costs – Other Selling Expenses – Remaining Mortgage Balance.
Cost Breakdown Table
Expense Category Estimated Amount
Estimated Sale Price $0.00
Agent Commission $0.00
Closing Costs $0.00
Repair Costs $0.00
Other Selling Expenses $0.00
Remaining Mortgage Balance $0.00
Total Estimated Selling Costs $0.00
Estimated Net Proceeds $0.00
Cost to Sell House Breakdown
Agent Commission Other Costs (Closing, Repairs, etc.) Mortgage Balance

What is the Cost to Sell House Calculation?

The cost to sell house calculation is a crucial financial tool designed to estimate the total expenses a homeowner will incur when selling their property. It goes beyond just the listing price to provide a realistic picture of the net proceeds you can expect to receive after all associated fees and costs are paid. Understanding these expenses is vital for accurate financial planning, whether you're buying a new home, investing, or simply managing your finances.

Who Should Use It:

  • Homeowners planning to sell their primary residence.
  • Real estate investors looking to liquidate properties.
  • Individuals needing to estimate net proceeds for future financial commitments.
  • Anyone curious about the true financial implications of selling a home.

Common Misconceptions:

  • Misconception: The sale price is the amount I'll receive. Reality: Numerous fees and costs are deducted before you get your money.
  • Misconception: Agent commission is the only significant cost. Reality: Closing costs, repairs, and outstanding mortgage balances can be substantial.
  • Misconception: Costs are fixed percentages. Reality: Some costs are negotiable, vary by location, or depend on the property's condition.

Cost to Sell House Formula and Mathematical Explanation

The cost to sell house calculation aims to determine the net amount of money a seller receives. It's derived by subtracting all selling-related expenses and outstanding debts from the agreed-upon sale price.

The Core Formula:

Net Proceeds = Sale Price - Total Selling Expenses - Remaining Mortgage Balance

Where Total Selling Expenses is further broken down:

Total Selling Expenses = Agent Commission + Closing Costs + Repair Costs + Other Selling Expenses

Substituting this back into the main formula:

Net Proceeds = Sale Price - (Agent Commission + Closing Costs + Repair Costs + Other Selling Expenses) - Remaining Mortgage Balance

Let's break down each variable:

Variables Used in the Cost to Sell House Calculation
Variable Meaning Unit Typical Range
Sale Price The agreed-upon price the buyer will pay for the property. $ Market Dependent
Agent Commission Rate The percentage of the sale price paid to the real estate agents (buyer's and seller's). % 4% – 6%
Closing Costs Rate A percentage of the sale price covering various fees like title insurance, escrow fees, attorney fees, recording fees, and transfer taxes. % 1% – 4%
Repair Costs Expenses incurred to fix or improve the property to make it more attractive or meet buyer/inspection requirements. $ Variable (can be $0 to significant amounts)
Other Selling Expenses Miscellaneous costs such as staging, professional cleaning, moving expenses, pre-sale inspections, or minor upgrades not classified as major repairs. $ Variable ($100s to $1000s)
Remaining Mortgage Balance The outstanding principal amount owed on the seller's current mortgage loan. $ Depends on loan terms and payments made
Agent Commission Amount Calculated as: Sale Price * (Agent Commission Rate / 100) $ Derived
Closing Costs Amount Calculated as: Sale Price * (Closing Costs Rate / 100) $ Derived
Total Selling Expenses Sum of Agent Commission Amount, Closing Costs Amount, Repair Costs, and Other Selling Expenses. $ Derived
Net Proceeds The final amount the seller takes home after all deductions. $ Derived

Practical Examples (Real-World Use Cases)

Let's illustrate the cost to sell house calculation with two distinct scenarios:

Example 1: Standard Home Sale

Sarah is selling her suburban home. She expects to sell it for $450,000. Her agent has agreed to a 5% commission. She estimates closing costs at 2.5% of the sale price, needs $3,000 in repairs, and has $1,500 in other expenses. Her remaining mortgage balance is $150,000.

  • Sale Price: $450,000
  • Agent Commission Rate: 5%
  • Closing Costs Rate: 2.5%
  • Repair Costs: $3,000
  • Other Selling Expenses: $1,500
  • Remaining Mortgage Balance: $150,000

Calculations:

  • Agent Commission Amount = $450,000 * (5 / 100) = $22,500
  • Closing Costs Amount = $450,000 * (2.5 / 100) = $11,250
  • Total Selling Expenses = $22,500 + $11,250 + $3,000 + $1,500 = $38,250
  • Net Proceeds = $450,000 – $38,250 – $150,000 = $261,750

Interpretation: Sarah can expect to net approximately $261,750 from the sale after covering all costs and her mortgage. This figure is crucial for her plans to purchase a new home.

Example 2: Higher-End Property with More Repairs

Mark is selling a luxury condo. The asking price is $1,200,000. The commission rate is 5.5%. He anticipates higher closing costs of 3% due to title complexities. The condo requires $15,000 in staging and minor renovations. His remaining mortgage is $600,000.

  • Sale Price: $1,200,000
  • Agent Commission Rate: 5.5%
  • Closing Costs Rate: 3%
  • Repair Costs: $15,000
  • Other Selling Expenses: $2,000 (staging, cleaning)
  • Remaining Mortgage Balance: $600,000

Calculations:

  • Agent Commission Amount = $1,200,000 * (5.5 / 100) = $66,000
  • Closing Costs Amount = $1,200,000 * (3 / 100) = $36,000
  • Total Selling Expenses = $66,000 + $36,000 + $15,000 + $2,000 = $119,000
  • Net Proceeds = $1,200,000 – $119,000 – $600,000 = $481,000

Interpretation: Mark's net proceeds are estimated at $481,000. The higher percentage for closing costs and significant repair/staging investment directly impact his final take-home amount. This calculation helps him assess profitability for his next investment.

How to Use This Cost to Sell House Calculator

Our cost to sell house calculator is designed for simplicity and accuracy. Follow these steps to get your personalized estimate:

  1. Enter Estimated Sale Price: Input the price you realistically expect your home to sell for.
  2. Input Agent Commission Rate: Enter the agreed-upon commission percentage with your real estate agent. If unsure, research typical rates in your area (often 4-6%).
  3. Estimate Closing Costs Rate: Provide an estimated percentage for closing costs. This covers various fees like title insurance, escrow, legal fees, and transfer taxes. A common range is 1-4%.
  4. Add Repair Costs: Enter the total amount you anticipate spending on necessary repairs or upgrades to prepare the house for sale.
  5. Include Other Selling Expenses: Factor in costs like staging, professional cleaning, moving, or any other miscellaneous selling expenses.
  6. State Remaining Mortgage Balance: Input the exact outstanding balance on your current mortgage. You can get this figure from your lender.
  7. Click 'Calculate Costs': Once all fields are populated, click the button. The calculator will instantly display your estimated net proceeds, commission amount, closing costs, and total selling expenses.

Reading Your Results:

  • Primary Result (Net Proceeds): This is the most important figure – the estimated amount of money you will receive after all costs are deducted.
  • Intermediate Values: These provide a breakdown of key expenses like agent commission and closing costs, helping you understand where the money is going.
  • Total Estimated Selling Costs: The sum of all expenses deducted from the sale price.

Decision-Making Guidance:

Use these results to:

  • Determine if the timing is right to sell based on your financial goals.
  • Negotiate effectively with agents regarding commission rates.
  • Budget accurately for repairs and staging.
  • Plan your next financial move, whether it's buying another property or investing.

Remember, this is an estimate. Actual costs can vary, so consult with your real estate agent and lender for precise figures. For more detailed financial planning, consider using a mortgage calculator.

Key Factors That Affect Cost to Sell House Results

Several factors significantly influence the final cost to sell house and, consequently, your net proceeds. Understanding these can help you prepare and potentially optimize your sale:

  1. Market Conditions: In a seller's market, homes may sell faster and potentially above asking price, reducing the impact of fixed costs. In a buyer's market, you might need to offer concessions or lower the price, increasing the percentage impact of fees.
  2. Real Estate Agent Commission: This is often the largest single expense. While typically 4-6%, rates can be negotiable, especially for higher-priced homes or if you're working with a discount brokerage. A 1% difference on a $500,000 sale is $5,000.
  3. Closing Costs Variability: Closing costs include a wide range of fees (title, escrow, legal, recording, taxes). These vary significantly by state, county, and even the specific title company or attorney used. Some states have higher transfer taxes than others.
  4. Property Condition and Required Repairs: Homes requiring significant repairs or updates will incur higher costs. Buyers often negotiate lower prices based on needed work. Investing wisely in repairs can sometimes yield a higher sale price, offsetting the initial cost.
  5. Staging and Presentation Costs: While optional, professional staging can help sell a home faster and for more money. The cost of staging, professional photography, and deep cleaning adds to your upfront expenses.
  6. Outstanding Mortgage and Liens: The remaining mortgage balance is a direct deduction from your proceeds. If you have other liens (e.g., home equity loan, tax liens), these must also be paid off at closing, further reducing your net amount.
  7. Home Warranty Costs: Sellers sometimes offer a home warranty to buyers for peace of mind. This is an additional upfront cost that protects against certain appliance or system failures for a year.
  8. Capital Gains Tax Implications: While not directly part of the selling expenses deducted at closing, potential capital gains tax on profits should be considered in your overall financial planning. Consult a tax advisor for specifics related to your situation. Using a capital gains tax calculator can help estimate this.

Frequently Asked Questions (FAQ)

What is the average cost to sell a house?
On average, the total cost to sell a house can range from 6% to 10% of the sale price, encompassing agent commissions, closing costs, repairs, and other expenses. Our calculator helps you estimate this based on your specific inputs.
Can I negotiate the agent commission?
Yes, agent commissions are typically negotiable. You can discuss the rate with your listing agent, especially if you are selling a high-value property or if the agent is providing fewer services.
Are closing costs negotiable?
Some closing costs, like title insurance fees or escrow fees, might be negotiable or you may have choices in providers. Others, like transfer taxes, are usually set by local government. Buyer-paid closing costs are also a common negotiation point.
Do I have to pay repairs before selling?
Not necessarily. You can either pay for repairs upfront, or buyers may request credits or a lower sale price to cover the needed work. The decision depends on your financial situation and market conditions.
What if the sale price is less than my mortgage balance?
This is called a short sale. You would need to negotiate with your lender to approve the sale for less than you owe. The lender typically covers the difference, but it can impact your credit score.
How long does it take to receive proceeds after closing?
Typically, proceeds are wired or disbursed within 1-3 business days after the closing is finalized, depending on the title company and your bank's processing times.
Does the cost to sell house calculator include capital gains tax?
No, this calculator focuses on the direct transactional costs of selling. Capital gains tax is a separate calculation based on your profit and individual tax situation. Consult a tax professional for advice. You might find a tax calculator useful for broader planning.
Can I use this calculator if I'm selling FSBO (For Sale By Owner)?
Yes! If you sell FSBO, you save on the seller's agent commission. Simply input 0% for the Agent Commission Rate to see your significantly reduced selling costs. You'll still have closing costs and other expenses.
document.addEventListener('DOMContentLoaded', function() { var faqQuestions = document.querySelectorAll('.faq-question'); faqQuestions.forEach(function(question) { question.addEventListener('click', function() { var answer = this.nextElementSibling; if (answer.style.display === 'block') { answer.style.display = 'none'; } else { answer.style.display = 'block'; } }); }); });

Related Tools and Internal Resources

© 2023 Your Financial Tools. All rights reserved. This calculator provides estimates for informational purposes only. Consult with a qualified real estate professional and financial advisor for personalized advice.
var salePriceInput = document.getElementById('salePrice'); var agentCommissionRateInput = document.getElementById('agentCommissionRate'); var closingCostsRateInput = document.getElementById('closingCostsRate'); var repairCostsInput = document.getElementById('repairCosts'); var otherCostsInput = document.getElementById('otherCosts'); var remainingMortgageInput = document.getElementById('remainingMortgage'); var salePriceError = document.getElementById('salePriceError'); var agentCommissionRateError = document.getElementById('agentCommissionRateError'); var closingCostsRateError = document.getElementById('closingCostsRateError'); var repairCostsError = document.getElementById('repairCostsError'); var otherCostsError = document.getElementById('otherCostsError'); var remainingMortgageError = document.getElementById('remainingMortgageError'); var netProceedsDisplay = document.getElementById('netProceeds'); var commissionAmountDisplay = document.getElementById('commissionAmount'); var closingCostsAmountDisplay = document.getElementById('closingCostsAmount'); var totalExpensesDisplay = document.getElementById('totalExpenses'); var tableSalePrice = document.getElementById('tableSalePrice'); var tableCommissionAmount = document.getElementById('tableCommissionAmount'); var tableClosingCostsAmount = document.getElementById('tableClosingCostsAmount'); var tableRepairCosts = document.getElementById('tableRepairCosts'); var tableOtherCosts = document.getElementById('tableOtherCosts'); var tableMortgageBalance = document.getElementById('tableMortgageBalance'); var tableTotalCosts = document.getElementById('tableTotalCosts'); var tableNetProceeds = document.getElementById('tableNetProceeds'); var chart; var chartContext = document.getElementById('costBreakdownChart').getContext('2d'); function formatCurrency(amount) { return '$' + amount.toFixed(2).replace(/\d(?=(\d{3})+\.)/g, '$&,'); } function validateInput(input, errorElement, min, max) { var value = parseFloat(input.value); var errorMsg = "; if (isNaN(value)) { errorMsg = 'Please enter a valid number.'; } else if (value max) { errorMsg = 'Value is too high.'; } errorElement.textContent = errorMsg; return errorMsg === "; } function calculateCosts() { var isValid = true; isValid &= validateInput(salePriceInput, salePriceError, 0); isValid &= validateInput(agentCommissionRateInput, agentCommissionRateError, 0, 10); isValid &= validateInput(closingCostsRateInput, closingCostsRateError, 0, 10); isValid &= validateInput(repairCostsInput, repairCostsError, 0); isValid &= validateInput(otherCostsInput, otherCostsError, 0); isValid &= validateInput(remainingMortgageInput, remainingMortgageError, 0); if (!isValid) { return; } var salePrice = parseFloat(salePriceInput.value); var agentCommissionRate = parseFloat(agentCommissionRateInput.value); var closingCostsRate = parseFloat(closingCostsRateInput.value); var repairCosts = parseFloat(repairCostsInput.value); var otherCosts = parseFloat(otherCostsInput.value); var remainingMortgage = parseFloat(remainingMortgageInput.value); var commissionAmount = salePrice * (agentCommissionRate / 100); var closingCostsAmount = salePrice * (closingCostsRate / 100); var totalExpenses = commissionAmount + closingCostsAmount + repairCosts + otherCosts; var netProceeds = salePrice – totalExpenses – remainingMortgage; commissionAmountDisplay.textContent = formatCurrency(commissionAmount); closingCostsAmountDisplay.textContent = formatCurrency(closingCostsAmount); totalExpensesDisplay.textContent = formatCurrency(totalExpenses); netProceedsDisplay.textContent = formatCurrency(netProceeds); tableSalePrice.textContent = formatCurrency(salePrice); tableCommissionAmount.textContent = formatCurrency(commissionAmount); tableClosingCostsAmount.textContent = formatCurrency(closingCostsAmount); tableRepairCosts.textContent = formatCurrency(repairCosts); tableOtherCosts.textContent = formatCurrency(otherCosts); tableMortgageBalance.textContent = formatCurrency(remainingMortgage); tableTotalCosts.textContent = formatCurrency(totalExpenses); tableNetProceeds.textContent = formatCurrency(netProceeds); updateChart(salePrice, commissionAmount, closingCostsAmount, repairCosts, otherCosts, remainingMortgage); } function resetCalculator() { salePriceInput.value = 500000; agentCommissionRateInput.value = 5; closingCostsRateInput.value = 2; repairCostsInput.value = 5000; otherCostsInput.value = 1000; remainingMortgageInput.value = 200000; salePriceError.textContent = "; agentCommissionRateError.textContent = "; closingCostsRateError.textContent = "; repairCostsError.textContent = "; otherCostsError.textContent = "; remainingMortgageError.textContent = "; calculateCosts(); } function copyResults() { var salePrice = parseFloat(salePriceInput.value); var agentCommissionRate = parseFloat(agentCommissionRateInput.value); var closingCostsRate = parseFloat(closingCostsRateInput.value); var repairCosts = parseFloat(repairCostsInput.value); var otherCosts = parseFloat(otherCostsInput.value); var remainingMortgage = parseFloat(remainingMortgageInput.value); var commissionAmount = salePrice * (agentCommissionRate / 100); var closingCostsAmount = salePrice * (closingCostsRate / 100); var totalExpenses = commissionAmount + closingCostsAmount + repairCosts + otherCosts; var netProceeds = salePrice – totalExpenses – remainingMortgage; var resultText = "— Cost to Sell House Estimate —\n\n"; resultText += "Key Assumptions:\n"; resultText += "- Estimated Sale Price: " + formatCurrency(salePrice) + "\n"; resultText += "- Agent Commission Rate: " + agentCommissionRate + "%\n"; resultText += "- Closing Costs Rate: " + closingCostsRate + "%\n"; resultText += "- Estimated Repair Costs: " + formatCurrency(repairCosts) + "\n"; resultText += "- Other Selling Expenses: " + formatCurrency(otherCosts) + "\n"; resultText += "- Remaining Mortgage Balance: " + formatCurrency(remainingMortgage) + "\n\n"; resultText += "Estimated Results:\n"; resultText += "Net Proceeds: " + formatCurrency(netProceeds) + "\n"; resultText += "Agent Commission: " + formatCurrency(commissionAmount) + "\n"; resultText += "Closing Costs: " + formatCurrency(closingCostsAmount) + "\n"; resultText += "Total Selling Expenses: " + formatCurrency(totalExpenses) + "\n"; navigator.clipboard.writeText(resultText).then(function() { alert('Results copied to clipboard!'); }).catch(function(err) { console.error('Failed to copy: ', err); alert('Failed to copy results. Please copy manually.'); }); } function updateChart(salePrice, commissionAmount, closingCostsAmount, repairCosts, otherCosts, remainingMortgage) { if (chart) { chart.destroy(); } var totalDeductions = commissionAmount + closingCostsAmount + repairCosts + otherCosts + remainingMortgage; var commissionPercentage = (commissionAmount / salePrice) * 100; var otherCostsTotal = closingCostsAmount + repairCosts + otherCosts; var otherCostsPercentage = (otherCostsTotal / salePrice) * 100; var mortgagePercentage = (remainingMortgage / salePrice) * 100; var remainingPercentage = (salePrice – totalDeductions) / salePrice * 100; if (isNaN(commissionPercentage)) commissionPercentage = 0; if (isNaN(otherCostsPercentage)) otherCostsPercentage = 0; if (isNaN(mortgagePercentage)) mortgagePercentage = 0; if (isNaN(remainingPercentage)) remainingPercentage = 0; chart = new Chart(chartContext, { type: 'pie', data: { labels: ['Agent Commission', 'Other Costs', 'Mortgage Balance', 'Net Proceeds'], datasets: [{ label: 'Percentage of Sale Price', data: [commissionPercentage, otherCostsPercentage, mortgagePercentage, remainingPercentage], backgroundColor: [ 'rgba(0, 74, 153, 0.8)', // Primary color for Commission 'rgba(40, 167, 69, 0.8)', // Success color for Other Costs 'rgba(108, 117, 125, 0.8)', // Muted color for Mortgage 'rgba(255, 193, 7, 0.8)' // Warning color for Net Proceeds ], borderColor: [ 'rgba(0, 74, 153, 1)', 'rgba(40, 167, 69, 1)', 'rgba(108, 117, 125, 1)', 'rgba(255, 193, 7, 1)' ], borderWidth: 1 }] }, options: { responsive: true, maintainAspectRatio: false, plugins: { legend: { position: 'bottom', }, title: { display: true, text: 'Breakdown as Percentage of Sale Price' }, tooltip: { callbacks: { label: function(context) { var label = context.label || "; if (label) { label += ': '; } if (context.parsed !== null) { var value = context.parsed; // Find the corresponding raw value for percentage calculation var dataset = context.chart.data.datasets[0]; var index = context.dataIndex; var rawValue; if (label.includes('Agent Commission')) rawValue = commissionAmount; else if (label.includes('Other Costs')) rawValue = otherCostsTotal; else if (label.includes('Mortgage Balance')) rawValue = remainingMortgage; else if (label.includes('Net Proceeds')) rawValue = salePrice – totalDeductions; else rawValue = 0; label += formatCurrency(rawValue) + ' (' + value.toFixed(2) + '%)'; } return label; } } } } } }); } // Initial calculation on page load document.addEventListener('DOMContentLoaded', calculateCosts);

Leave a Comment