How to Calculate Weighted Average Lease Term Asc 842

Calculate Weighted Average Lease Term (ASC 842) body { font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; background-color: #f8f9fa; color: #333; line-height: 1.6; margin: 0; padding: 0; } .container { max-width: 1000px; margin: 20px auto; padding: 20px; background-color: #fff; border-radius: 8px; box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1); display: flex; flex-direction: column; align-items: center; } h1, h2, h3 { color: #004a99; text-align: center; } h1 { font-size: 2.2em; margin-bottom: 10px; } h2 { font-size: 1.8em; margin-top: 30px; margin-bottom: 15px; } h3 { font-size: 1.4em; margin-top: 20px; margin-bottom: 10px; } .summary { font-size: 1.1em; color: #555; margin-bottom: 30px; text-align: center; } .loan-calc-container { background-color: #eef5ff; padding: 30px; border-radius: 8px; width: 100%; box-sizing: border-box; margin-bottom: 30px; border: 1px solid #cce0ff; } .input-group { margin-bottom: 20px; width: 100%; } .input-group label { display: block; margin-bottom: 8px; font-weight: bold; color: #004a99; } .input-group input[type="number"], .input-group input[type="text"], .input-group select { width: calc(100% – 24px); padding: 12px; border: 1px solid #ccc; border-radius: 4px; font-size: 1em; box-sizing: border-box; } .input-group .helper-text { font-size: 0.85em; color: #666; margin-top: 5px; display: block; } .input-group .error-message { color: #dc3545; font-size: 0.9em; margin-top: 5px; display: none; /* Hidden by default */ } .button-group { display: flex; justify-content: space-between; margin-top: 25px; flex-wrap: wrap; gap: 10px; } button { padding: 12px 20px; border: none; border-radius: 5px; cursor: pointer; font-size: 1em; font-weight: bold; transition: background-color 0.3s ease, transform 0.2s ease; flex: 1 1 auto; min-width: 150px; } button.primary { background-color: #004a99; color: white; } button.primary:hover { background-color: #003b7a; transform: translateY(-1px); } button.secondary { background-color: #6c757d; color: white; } button.secondary:hover { background-color: #5a6268; transform: translateY(-1px); } button.tertiary { background-color: #ffc107; color: #212529; } button.tertiary:hover { background-color: #e0a800; transform: translateY(-1px); } #results-container { margin-top: 30px; padding: 25px; background-color: #e9ecef; border-radius: 8px; width: 100%; box-sizing: border-box; border: 1px solid #ced4da; } .result-item { display: flex; justify-content: space-between; align-items: center; margin-bottom: 15px; padding: 10px; background-color: #ffffff; border-radius: 4px; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05); } .result-item label { font-weight: normal; color: #333; margin-bottom: 0; } .result-item .value { font-size: 1.3em; font-weight: bold; color: #004a99; } #waltResult { font-size: 2em; color: #28a745; background-color: #d4edda; padding: 15px; text-align: center; border-radius: 5px; margin-bottom: 20px; font-weight: bold; } #formula-explanation { margin-top: 20px; font-style: italic; color: #555; text-align: center; font-size: 0.95em; } table { width: 100%; border-collapse: collapse; margin-top: 20px; margin-bottom: 30px; } th, td { border: 1px solid #ddd; padding: 10px; text-align: right; } th { background-color: #004a99; color: white; text-align: center; } td:first-child, th:first-child { text-align: left; } tr:nth-child(even) { background-color: #f2f2f2; } caption { font-size: 1.1em; font-weight: bold; margin-bottom: 10px; caption-side: top; text-align: left; color: #004a99; } canvas { display: block; margin: 20px auto; background-color: #fff; border-radius: 8px; box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1); } .article-section { margin-top: 40px; padding-top: 20px; border-top: 1px solid #eee; } .article-section:first-child { margin-top: 0; padding-top: 0; border-top: none; } .faq-item { margin-bottom: 15px; } .faq-item h3 { margin-bottom: 5px; cursor: pointer; color: #004a99; text-align: left; } .faq-item p { margin-top: 0; padding-left: 15px; border-left: 3px solid #004a99; color: #555; display: none; /* Hidden by default */ } .internal-links ul { list-style: none; padding: 0; } .internal-links li { margin-bottom: 10px; } .internal-links a { color: #004a99; text-decoration: none; font-weight: bold; } .internal-links a:hover { text-decoration: underline; } .internal-links span { color: #666; font-size: 0.9em; display: block; margin-top: 3px; } .error-active .error-message { display: block; } .input-group input:focus, .input-group select:focus { border-color: #004a99; outline: none; box-shadow: 0 0 5px rgba(0, 74, 153, 0.3); } .highlighted-result { background-color: #d4edda; color: #155724; font-weight: bold; padding: 20px; text-align: center; border-radius: 5px; margin-bottom: 25px; font-size: 1.8em; border: 1px solid #c3e6cb; }

Calculate Weighted Average Lease Term (ASC 842)

Understand and calculate your Weighted Average Lease Term (WALT) according to ASC 842 lease accounting standards. This calculator helps lessees determine the average lease term, a crucial factor in lease classification and accounting treatment.

Lease Details Input

Enter the total number of leases to include.

Calculation Results

Understanding Weighted Average Lease Term (WALT) under ASC 842

What is Weighted Average Lease Term (WALT)?

The Weighted Average Lease Term (WALT) is a key metric used in lease accounting, particularly under the ASC 842 standard. It represents the average lease term, with each lease weighted by its respective lease payments. In simpler terms, it's a way to smooth out the differing lengths of various lease agreements into a single, representative term. This calculation is critical for lessees in determining the classification of their leases. Leases with a term of 12 months or less, at commencement, can be exempt from recognizing most ASC 842 lease accounting principles, including the right-of-use asset and lease liability. WALT helps in assessing if the overall portfolio or a significant portion of leases might qualify for this short-term lease exemption or influences other accounting considerations.

Who should use it? Lessees (companies leasing assets) are the primary users of WALT calculations under ASC 842. It's particularly relevant for companies with a diverse portfolio of lease agreements across various asset types (e.g., real estate, equipment, vehicles). Understanding WALT assists finance and accounting teams in applying the lease accounting standard correctly, ensuring compliance and accurate financial reporting.

Common Misconceptions:

  • WALT equals the simple average of lease terms: This is incorrect. WALT specifically weights lease terms by their payment amounts, giving more influence to leases with higher payments.
  • WALT is only for new leases: While critical at commencement, WALT might be reassessed under specific circumstances (e.g., significant lease modifications).
  • WALT determines lease classification alone: WALT is one factor. The lease term (including optional periods the lessee is reasonably certain to exercise) is the primary driver for the short-term lease exemption. WALT provides an aggregate view.

WALT Formula and Mathematical Explanation

The calculation of the Weighted Average Lease Term (WALT) under ASC 842 involves summing the product of each lease's term and its associated lease payments, and then dividing by the total lease payments across all leases considered. This methodology ensures that leases with higher payment obligations have a greater impact on the average term.

The formula can be expressed as:

WALT = Σ (Lease Termᵢ * Lease Paymentsᵢ) / Σ (Lease Paymentsᵢ)

Where:

  • Σ denotes summation across all leases (i).
  • Lease Termᵢ is the term of the individual lease agreement (i) in months or years.
  • Lease Paymentsᵢ is the total payments associated with lease agreement (i) over its term.

Variable Explanations Table

Variable Meaning Unit Typical Range
Lease Termᵢ The duration of an individual lease agreement, including reasonably certain renewal or termination options. Months or Years 12 months to 20+ years
Lease Paymentsᵢ The sum of all payments required under the lease agreement over its term. This typically includes fixed payments, variable payments based on an index or rate, and residual value guarantees the lessee is expected to make. Excludes payments for executory costs (e.g., maintenance, insurance) borne by the lessor. Currency Amount (e.g., USD) Variable, depends on asset value and term
Total Lease Payments The sum of Lease Paymentsᵢ for all leases included in the WALT calculation. Currency Amount (e.g., USD) Sum of individual lease payments
WALT Weighted Average Lease Term. The result of the calculation. Months or Years Typically between the shortest and longest lease term, weighted by payments.

Practical Examples (Real-World Use Cases)

Example 1: Small Retail Portfolio

A small business leases three retail spaces. They need to determine their WALT to assess their overall lease portfolio exposure.

  • Lease A (High-Traffic Location): Term: 5 years (60 months), Annual Payments: $50,000. Total Payments = $250,000.
  • Lease B (Standard Location): Term: 3 years (36 months), Annual Payments: $30,000. Total Payments = $90,000.
  • Lease C (Satellite Kiosk): Term: 2 years (24 months), Annual Payments: $10,000. Total Payments = $20,000.

Calculation:

  • Weighted Term A: 60 months * $250,000 = 15,000,000 month-dollars
  • Weighted Term B: 36 months * $90,000 = 3,240,000 month-dollars
  • Weighted Term C: 24 months * $20,000 = 480,000 month-dollars
  • Total Weighted Term = 15,000,000 + 3,240,000 + 480,000 = 18,720,000 month-dollars
  • Total Lease Payments = $250,000 + $90,000 + $20,000 = $360,000
  • WALT = 18,720,000 / $360,000 = 52 months (or approx. 4.33 years)

Interpretation: Although the simple average term is (60+36+24)/3 = 40 months, the WALT is 52 months due to the high payment weighting of Lease A. This longer weighted term suggests the business has significant long-term lease commitments impacting its financial statements under ASC 842.

Example 2: Corporate Equipment Fleet

A corporation is evaluating its fleet of leased vehicles.

  • Lease D (Trucks): Term: 4 years (48 months), Total Payments: $120,000.
  • Lease E (Sedans): Term: 3 years (36 months), Total Payments: $80,000.
  • Lease F (Specialty Vans): Term: 5 years (60 months), Total Payments: $150,000.

Calculation:

  • Weighted Term D: 48 months * $120,000 = 5,760,000 month-dollars
  • Weighted Term E: 36 months * $80,000 = 2,880,000 month-dollars
  • Weighted Term F: 60 months * $150,000 = 9,000,000 month-dollars
  • Total Weighted Term = 5,760,000 + 2,880,000 + 9,000,000 = 17,640,000 month-dollars
  • Total Lease Payments = $120,000 + $80,000 + $150,000 = $350,000
  • WALT = 17,640,000 / $350,000 = 50.4 months (or approx. 4.2 years)

Interpretation: The WALT of 50.4 months indicates a significant commitment. This is influenced heavily by the longer term and higher payments of the specialty vans. This WALT is essential for reporting the correct lease liability and right-of-use asset values on the balance sheet.

How to Use This WALT Calculator

Our Weighted Average Lease Term calculator simplifies the ASC 842 WALT calculation process. Follow these steps for accurate results:

  1. Enter the Number of Leases: Start by inputting the total count of individual lease agreements you wish to include in the WALT calculation.
  2. Input Lease Details: For each lease, you will need to provide:
    • Lease Term (Months): Enter the duration of the lease in months. Remember to include any reasonably certain renewal periods or account for termination options.
    • Total Lease Payments: Input the sum of all expected payments under that specific lease agreement over its entire term. Exclude payments for separate services like maintenance unless they are irrevocably bundled.
  3. Calculate: Click the "Calculate WALT" button. The calculator will automatically compute the weighted average lease term and display key intermediate values.
  4. Review Results:
    • WALT: The primary result, shown in months. This is your weighted average lease term.
    • Total Weighted Term: The sum of (Lease Term * Total Lease Payments) for all leases.
    • Total Lease Payments: The aggregate of all lease payments entered.
    • Formula Explanation: A brief reminder of how WALT is calculated.
  5. Make Decisions: Use the WALT result, along with individual lease terms and payment information, to inform your lease classification decisions under ASC 842. A high WALT might indicate a portfolio dominated by longer-term leases, while a lower WALT could suggest a greater proportion of shorter-term agreements.
  6. Reset: If you need to start over or adjust inputs, click the "Reset" button to return to default values.
  7. Copy Results: Use the "Copy Results" button to easily transfer the calculated WALT, intermediate values, and key assumptions to your reports or documentation.

Key Factors Affecting WALT Results

Several factors significantly influence the calculation and interpretation of the Weighted Average Lease Term (WALT) under ASC 842:

  1. Lease Term Inclusions: The definition of "lease term" under ASC 842 is crucial. It includes the non-cancellable period plus any periods covered by options to extend or terminate the lease if the lessee is reasonably certain to exercise those options. Options that are not reasonably certain to be exercised should be excluded, significantly impacting WALT.
  2. Lease Payment Definitions: Accurately identifying and summing all "lease payments" is vital. This includes fixed payments, variable payments tied to an index or rate, and amounts expected to be paid under residual value guarantees. Payments for non-lease components (e.g., separate maintenance contracts) should be excluded or allocated separately. Leases with higher total payment obligations will disproportionately influence WALT.
  3. Optional Periods: The decision to include or exclude optional renewal or termination periods hinges on the "reasonably certain" assessment. Management judgment plays a significant role here. A lessee's behavior, economic incentives, and the potential for asset obsolescence all factor into this assessment, directly affecting the lease term used in WALT.
  4. Lease Modifications: Significant modifications to a lease (e.g., adding or removing assets, extending or shortening the term) may require reassessment and can impact the calculated WALT. Accounting for these modifications correctly is essential for ongoing compliance.
  5. Economic Environment & Interest Rates: While WALT itself doesn't directly incorporate interest rates (unlike lease liability calculations), the prevailing economic conditions and interest rate environment can influence decisions regarding lease renewals or terminations. Higher rates might make early termination less attractive, potentially increasing the likelihood of exercising options and thus extending the effective lease term used in WALT.
  6. Asset Type and Usage: The nature of the leased asset and how it is expected to be used can inform judgments about renewal options. For instance, specialized equipment with a short useful life might have less certainty around renewal options compared to a standard office building lease, affecting the term used in WALT.
  7. Lease vs. Buy Decisions: The strategic decision to lease rather than purchase assets can influence the overall structure and length of lease agreements. A company favoring leasing might have a more complex portfolio with varying terms, making WALT a more critical metric for understanding their lease exposure.

Frequently Asked Questions (FAQ)

Q1: Is WALT the same as the lease term for short-term lease exemptions?

No. The short-term lease exemption (typically 12 months or less) applies on a lease-by-lease basis using the individual lease's term, not the WALT. WALT provides an aggregate view of the lease portfolio's average duration.

Q2: Do I need to recalculate WALT regularly?

WALT is primarily calculated at the commencement of the lease. However, it should be reassessed if a lease modification occurs that substantively changes the lease term or payments.

Q3: How are variable lease payments included in WALT?

Variable payments based on an index or rate are included in the total lease payments used for WALT calculation using their value at lease commencement. Future changes in the index/rate are not considered for the initial WALT calculation unless they trigger a modification.

Q4: What if a lease has zero payments but is still a lease (e.g., peppercorn rent)?

If a lease has minimal or zero cash payments but conveys the right to use an asset, it still requires accounting under ASC 842. For WALT, such a lease would contribute zero to the 'Total Lease Payments' and zero to the 'Total Weighted Term', effectively having no impact on the WALT calculation itself, though the lease still needs to be recognized if it meets the definition.

Q5: Does WALT affect the right-of-use (ROU) asset or lease liability amounts?

WALT itself doesn't directly determine the ROU asset or lease liability amounts. These are calculated based on the specific lease term, lease payments, and discount rate for each individual lease. However, WALT is a factor in assessing whether a lease qualifies for the short-term exemption, which *would* exempt it from ROU asset and lease liability recognition.

Q6: Should I use months or years for the lease term?

Consistency is key. Most practitioners use months because lease terms are often quoted in months, and it avoids potential rounding issues. Ensure the unit used for the lease term is the same unit used for the final WALT output.

Q7: How do I handle renewal options I'm not sure about?

The "reasonably certain" assessment is crucial. If management cannot conclude that an option is reasonably certain to be exercised based on economic facts and business reasons, it should not be included in the lease term for WALT calculation or lease classification purposes.

Q8: What if my leases have significantly different payment structures (e.g., lump sum vs. monthly)?

The calculator handles this by asking for the *total* lease payments for the entire term. Whether those payments are made monthly, annually, or as a lump sum, you sum them all up to get the 'Total Lease Payments' for that specific lease (Lease Paymentsᵢ).

Related Tools and Internal Resources

Lease Term vs. Payment Distribution

Chart showing the distribution of lease terms and their corresponding total payment amounts.

© 2023 Your Company Name. All rights reserved.

var leaseInputs = []; // Store references to dynamically created input groups function validateInput(element, errorElement, min, max, isEmptyAllowed) { var value = element.value.trim(); var errorDiv = document.getElementById(errorElement); errorDiv.style.display = 'none'; // Hide error initially element.parentNode.classList.remove('error-active'); // Remove error class if (!isEmptyAllowed && value === ") { errorDiv.innerText = 'This field is required.'; errorDiv.style.display = 'block'; element.parentNode.classList.add('error-active'); return false; } if (value !== ") { var numValue = parseFloat(value); if (isNaN(numValue)) { errorDiv.innerText = 'Please enter a valid number.'; errorDiv.style.display = 'block'; element.parentNode.classList.add('error-active'); return false; } if (min !== null && numValue max) { errorDiv.innerText = 'Value cannot exceed ' + max + '.'; errorDiv.style.display = 'block'; element.parentNode.classList.add('error-active'); return false; } } return true; } function addLeaseEntry(index, termMonths, totalPayments) { var leaseEntriesDiv = document.getElementById('leaseEntries'); var div = document.createElement('div'); div.id = 'leaseEntry' + index; div.className = 'input-group'; div.innerHTML = `

Lease #${index + 1} Details

Enter the duration of the lease in months.
Sum of all payments for this lease over its term.
`; leaseEntriesDiv.appendChild(div); // Add event listeners for real-time validation var termInput = document.getElementById('termMonths' + index); var paymentsInput = document.getElementById('totalPayments' + index); termInput.oninput = function() { validateInput(this, 'termMonthsError' + index, 1, null, false); calculateWALT(); }; paymentsInput.oninput = function() { validateInput(this, 'totalPaymentsError' + index, 0, null, false); calculateWALT(); }; leaseInputs.push({ term: termInput, payments: paymentsInput }); } function createLeaseEntries() { var numLeasesInput = document.getElementById('numLeases'); var numLeases = parseInt(numLeasesInput.value); var leaseEntriesDiv = document.getElementById('leaseEntries'); leaseEntriesDiv.innerHTML = "; // Clear existing entries leaseInputs = []; // Reset the array if (isNaN(numLeases) || numLeases < 1) { numLeasesInput.value = 1; numLeases = 1; } // Sensible defaults for the first few leases var defaultTerms = [36, 60, 24]; var defaultPayments = [50000, 120000, 20000]; for (var i = 0; i < numLeases; i++) { addLeaseEntry(i, defaultTerms[i], defaultPayments[i]); } calculateWALT(); // Calculate initial values } function calculateWALT() { var totalWeightedTerm = 0; var totalPayments = 0; var leases = []; var allValid = true; var numLeasesInput = document.getElementById('numLeases'); var numLeases = parseInt(numLeasesInput.value); // Validate number of leases input separately if (!validateInput(numLeasesInput, 'numLeasesError', 1, null, false)) { allValid = false; } for (var i = 0; i 0) { walt = totalWeightedTerm / totalPayments; } displayResults(walt, totalWeightedTerm, totalPayments, leases); updateChart(leases); } function displayResults(walt, totalWeightedTerm, totalPayments, leases) { var waltResultDiv = document.getElementById('waltResult'); var intermediateResultsDiv = document.getElementById('intermediateResults'); var formulaExplanationDiv = document.getElementById('formula-explanation'); var waltDisplay = '–'; var formulaText = 'WALT = Σ (Lease Termᵢ * Lease Paymentsᵢ) / Σ (Lease Paymentsᵢ)'; if (totalPayments > 0) { waltDisplay = walt.toFixed(2) + ' months'; formulaText = 'WALT = (' + totalWeightedTerm.toLocaleString(undefined, { minimumFractionDigits: 0, maximumFractionDigits: 0 }) + ' month-dollars) / (' + totalPayments.toLocaleString(undefined, { minimumFractionDigits: 0, maximumFractionDigits: 2 }) + ') = ' + walt.toFixed(2) + ' months'; } else if (leaseInputs.length > 0) { waltDisplay = '0.00 months'; // Handle case with leases but zero payments formulaText = 'WALT = 0 months (Total lease payments are zero)'; } waltResultDiv.innerText = waltDisplay; intermediateResultsDiv.innerHTML = `
${totalWeightedTerm.toLocaleString(undefined, { minimumFractionDigits: 0, maximumFractionDigits: 0 })} month-dollars
$${totalPayments.toLocaleString(undefined, { minimumFractionDigits: 2, maximumFractionDigits: 2 })}
${leaseInputs.length}
`; formulaExplanationDiv.innerText = formulaText; // Add table for lease details var tableHtml = ` `; leases.forEach(function(lease) { tableHtml += ` `; }); tableHtml += `
Individual Lease Details
Lease # Term (Months) Total Payments Weighted Term (Month-Dollars)
${lease.id} ${lease.term} $${lease.payments.toLocaleString(undefined, { minimumFractionDigits: 2, maximumFractionDigits: 2 })} ${lease.weightedTerm.toLocaleString(undefined, { minimumFractionDigits: 0, maximumFractionDigits: 0 })}
`; intermediateResultsDiv.insertAdjacentHTML('afterend', tableHtml); } function resetForm() { document.getElementById('numLeases').value = 3; createLeaseEntries(); // Recreates entries with default values // Clear any lingering error messages var errorMessages = document.querySelectorAll('.error-message'); for (var i = 0; i < errorMessages.length; i++) { errorMessages[i].style.display = 'none'; errorMessages[i].parentNode.classList.remove('error-active'); } // Reset input group error states var errorActiveGroups = document.querySelectorAll('.input-group.error-active'); for (var i = 0; i < errorActiveGroups.length; i++) { errorActiveGroups[i].classList.remove('error-active'); } } function copyResults() { var waltResult = document.getElementById('waltResult').innerText; var intermediateValues = document.getElementById('intermediateResults').innerText; // This gets all text content, including table var formula = document.getElementById('formula-explanation').innerText; // Extracting specific intermediate values if needed, otherwise text content is fine var totalWeightedTerm = document.querySelector('#intermediateResults .result-item:nth-of-type(1) .value').innerText; var totalPayments = document.querySelector('#intermediateResults .result-item:nth-of-type(2) .value').innerText; var numLeases = document.querySelector('#intermediateResults .result-item:nth-of-type(3) .value').innerText; var leaseTable = document.querySelector('#intermediateResults table'); var tableRows = leaseTable.querySelectorAll('tr'); var tableString = "Lease Details:\n"; tableRows.forEach(function(row) { var cells = row.querySelectorAll('th, td'); var rowText = []; cells.forEach(function(cell) { rowText.push(cell.innerText.replace(/\n/g, ' ')); // Clean up potential newlines within cells }); tableString += rowText.join('\t') + '\n'; // Use tab for column separation }); var textToCopy = `Weighted Average Lease Term (WALT) Calculation Results:\n\n` + `Primary Result (WALT): ${waltResult}\n\n` + `Key Assumptions:\n` + ` Number of Leases: ${numLeases}\n` + ` Total Lease Payments: ${totalPayments}\n` + ` Total Weighted Term: ${totalWeightedTerm}\n\n` + `Formula Used: ${formula}\n\n` + `${tableString}`; if (navigator.clipboard && window.isSecureContext) { navigator.clipboard.writeText(textToCopy).then(function() { alert('Results copied to clipboard!'); }).catch(function(err) { console.error('Failed to copy text: ', err); fallbackCopyTextToClipboard(textToCopy); }); } else { fallbackCopyTextToClipboard(textToCopy); } } // Fallback for older browsers or insecure contexts function fallbackCopyTextToClipboard(text) { var textArea = document.createElement("textarea"); textArea.value = text; textArea.style.position = "fixed"; textArea.style.left = "-9999px"; textArea.style.top = "-9999px"; document.body.appendChild(textArea); textArea.focus(); textArea.select(); try { var successful = document.execCommand('copy'); var msg = successful ? 'Results copied to clipboard!' : 'Failed to copy results.'; alert(msg); } catch (err) { console.error('Fallback: Oops, unable to copy', err); alert('Failed to copy results. Please copy manually.'); } document.body.removeChild(textArea); } function toggleFaq(header) { var content = header.nextElementSibling; var display = window.getComputedStyle(content).display; if (display === 'none') { content.style.display = 'block'; header.style.fontWeight = 'bold'; } else { content.style.display = 'none'; header.style.fontWeight = 'normal'; } } // Charting Logic var waltChartInstance = null; function updateChart(leases) { var ctx = document.getElementById('waltChart').getContext('2d'); if (waltChartInstance) { waltChartInstance.destroy(); // Destroy previous chart instance } var labels = []; var paymentData = []; var termData = []; leases.forEach(function(lease, index) { labels.push('Lease #' + (index + 1)); paymentData.push(lease.payments); termData.push(lease.term); }); waltChartInstance = new Chart(ctx, { type: 'bar', // Using bar chart for better comparison data: { labels: labels, datasets: [{ label: 'Total Lease Payments', data: paymentData, backgroundColor: 'rgba(0, 74, 153, 0.6)', // Primary color borderColor: 'rgba(0, 74, 153, 1)', borderWidth: 1, yAxisID: 'y-axis-payments' }, { label: 'Lease Term (Months)', data: termData, backgroundColor: 'rgba(40, 167, 69, 0.6)', // Success color borderColor: 'rgba(40, 167, 69, 1)', borderWidth: 1, yAxisID: 'y-axis-term' }] }, options: { responsive: true, maintainAspectRatio: true, scales: { x: { title: { display: true, text: 'Lease Number' } }, y-axis-payments: { type: 'linear', position: 'left', title: { display: true, text: 'Total Payments ($)' }, ticks: { beginAtZero: true } }, y-axis-term: { type: 'linear', position: 'right', title: { display: true, text: 'Term (Months)' }, ticks: { beginAtZero: true }, grid: { drawOnChartArea: false, // only want the grid lines for one axis to show up } } }, plugins: { legend: { position: 'top', }, title: { display: true, text: 'Lease Payments vs. Term by Lease' } } } }); } // Initial setup on page load window.onload = function() { // Add Chart.js library dynamically if not already present if (typeof Chart === 'undefined') { var script = document.createElement('script'); script.src = 'https://cdn.jsdelivr.net/npm/chart.js'; script.onload = function() { createLeaseEntries(); // Create entries after chart library is loaded }; document.head.appendChild(script); } else { createLeaseEntries(); // Create entries if Chart.js is already loaded } };

Leave a Comment