Dirt Removal Cost Calculator & Guide
:root {
–primary-color: #004a99;
–success-color: #28a745;
–background-color: #f8f9fa;
–text-color: #333;
–border-color: #ddd;
–shadow-color: rgba(0, 0, 0, 0.1);
–card-background: #fff;
–error-color: #dc3545;
}
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;
display: flex;
flex-direction: column;
align-items: center;
}
.container {
width: 100%;
max-width: 960px;
margin: 20px auto;
padding: 20px;
background-color: var(–card-background);
border-radius: 8px;
box-shadow: 0 4px 12px var(–shadow-color);
}
h1, h2, h3 {
color: var(–primary-color);
text-align: center;
margin-bottom: 20px;
}
h1 {
font-size: 2.5em;
}
h2 {
font-size: 1.8em;
margin-top: 30px;
border-bottom: 2px solid var(–primary-color);
padding-bottom: 10px;
}
h3 {
font-size: 1.4em;
margin-top: 25px;
color: var(–primary-color);
}
.loan-calc-container {
background-color: var(–card-background);
padding: 30px;
border-radius: 8px;
box-shadow: 0 2px 8px var(–shadow-color);
margin-bottom: 30px;
}
.input-group {
margin-bottom: 20px;
text-align: left;
}
.input-group label {
display: block;
margin-bottom: 8px;
font-weight: bold;
color: var(–primary-color);
}
.input-group input[type="number"],
.input-group input[type="text"],
.input-group select {
width: calc(100% – 22px);
padding: 10px;
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 {
border-color: var(–primary-color);
outline: none;
box-shadow: 0 0 0 2px rgba(0, 74, 153, 0.2);
}
.input-group .helper-text {
font-size: 0.85em;
color: #6c757d;
margin-top: 5px;
display: block;
}
.error-message {
color: var(–error-color);
font-size: 0.85em;
margin-top: 5px;
display: none; /* Hidden by default */
}
.error-message.visible {
display: block;
}
.button-group {
display: flex;
justify-content: space-between;
margin-top: 30px;
gap: 10px;
}
.button-group button,
.button-group input[type="button"] {
padding: 12px 20px;
border: none;
border-radius: 5px;
cursor: pointer;
font-size: 1em;
font-weight: bold;
transition: background-color 0.3s ease;
flex: 1;
text-align: center;
}
.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: var(–success-color);
color: white;
}
.btn-copy:hover {
background-color: #218838;
}
#results {
margin-top: 30px;
padding: 25px;
background-color: var(–primary-color);
color: white;
border-radius: 8px;
text-align: center;
box-shadow: 0 4px 10px rgba(0, 74, 153, 0.3);
}
#results h3 {
color: white;
margin-bottom: 15px;
}
.primary-result {
font-size: 2.2em;
font-weight: bold;
margin-bottom: 10px;
display: block;
}
.intermediate-results div {
margin-bottom: 8px;
font-size: 1.1em;
}
.formula-explanation {
font-size: 0.9em;
color: rgba(255, 255, 255, 0.8);
margin-top: 15px;
border-top: 1px solid rgba(255, 255, 255, 0.2);
padding-top: 10px;
}
table {
width: 100%;
border-collapse: collapse;
margin-top: 20px;
margin-bottom: 30px;
box-shadow: 0 2px 8px var(–shadow-color);
}
th, td {
padding: 12px 15px;
text-align: left;
border-bottom: 1px solid var(–border-color);
}
thead {
background-color: var(–primary-color);
color: white;
}
th {
font-weight: bold;
}
tbody tr:nth-child(even) {
background-color: #f2f2f2;
}
caption {
font-size: 1.1em;
font-weight: bold;
color: var(–primary-color);
margin-bottom: 10px;
caption-side: top;
text-align: left;
}
.chart-container {
width: 100%;
max-width: 700px;
margin: 30px auto;
padding: 20px;
background-color: var(–card-background);
border-radius: 8px;
box-shadow: 0 2px 8px var(–shadow-color);
text-align: center;
}
.chart-container h3 {
margin-bottom: 20px;
}
canvas {
max-width: 100%;
height: auto;
}
.article-section {
margin-top: 40px;
padding: 30px;
background-color: var(–card-background);
border-radius: 8px;
box-shadow: 0 2px 8px var(–shadow-color);
margin-bottom: 30px;
}
.article-section h2 {
text-align: left;
border-bottom: 2px solid var(–primary-color);
padding-bottom: 10px;
margin-bottom: 20px;
}
.article-section h3 {
text-align: left;
color: var(–primary-color);
margin-top: 25px;
margin-bottom: 15px;
}
.article-section p {
margin-bottom: 15px;
}
.article-section ul,
.article-section ol {
margin-left: 20px;
margin-bottom: 15px;
}
.article-section li {
margin-bottom: 8px;
}
.faq-item {
margin-bottom: 15px;
border-left: 3px solid var(–primary-color);
padding-left: 15px;
}
.faq-item strong {
color: var(–primary-color);
display: block;
margin-bottom: 5px;
}
.internal-links-section {
margin-top: 40px;
padding: 30px;
background-color: var(–card-background);
border-radius: 8px;
box-shadow: 0 2px 8px var(–shadow-color);
margin-bottom: 30px;
}
.internal-links-section h2 {
text-align: left;
border-bottom: 2px solid var(–primary-color);
padding-bottom: 10px;
margin-bottom: 20px;
}
.internal-links-section ul {
list-style: none;
padding: 0;
}
.internal-links-section li {
margin-bottom: 15px;
border-bottom: 1px dashed var(–border-color);
padding-bottom: 10px;
}
.internal-links-section li:last-child {
border-bottom: none;
padding-bottom: 0;
}
.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: #6c757d;
margin-top: 5px;
}
/* Responsive adjustments */
@media (max-width: 768px) {
.container {
margin: 10px auto;
padding: 15px;
}
h1 {
font-size: 2em;
}
h2 {
font-size: 1.5em;
}
.button-group {
flex-direction: column;
gap: 10px;
}
.button-group button,
.button-group input[type="button"] {
width: 100%;
}
#results {
padding: 20px;
}
.primary-result {
font-size: 1.8em;
}
}
Dirt Removal Cost Calculator
Estimate the cost of removing dirt, soil, or debris from your project site. Input your project details below to get a quick estimate.
Dirt Removal Cost Estimator
Estimated Dirt Removal Cost
Formula Used: Total Cost = (Total Weight in Tons * Disposal Fee per Ton) + (Volume in yd³ * Transport Cost per yd³) + (Equipment Rental Cost per Day * Number of Project Days)
Cost Breakdown by Component
Key Assumptions & Variables
| Variable |
Meaning |
Unit |
Typical Range |
| Volume of Dirt |
Total amount of soil/debris to be removed. |
Cubic Yards (yd³) |
1 – 1000+ |
| Dirt Density |
Weight of dirt per unit volume. Varies by soil type and moisture. |
lbs/yd³ |
2500 – 3000 |
| Disposal Fee |
Cost charged by landfill/transfer station per ton of waste. |
$/Ton |
$20 – $100+ |
| Transport Cost |
Cost to haul one cubic yard of dirt to the disposal site. |
$/yd³ |
$50 – $150+ |
| Equipment Rental |
Daily cost for machinery like excavators, skid steers. |
$/Day |
$150 – $500+ |
| Project Days |
Estimated duration of the dirt removal operation. |
Days |
1 – 10+ |
What is Dirt Removal Cost Estimation?
Dirt removal cost estimation is the process of calculating the anticipated expenses involved in excavating, hauling, and disposing of soil, debris, or other materials from a construction site, landscaping project, or any area requiring excavation. This involves understanding various cost components, from the sheer volume and weight of the material to transportation logistics, disposal fees, and equipment usage.
Who should use it: This estimation is crucial for homeowners planning renovations or landscaping, contractors managing construction projects, developers assessing project feasibility, and anyone needing to clear land. Accurate estimation helps in budgeting, securing financing, and preventing cost overruns.
Common misconceptions: A frequent misconception is that dirt removal is a simple per-truckload charge. In reality, costs are multifaceted, influenced by factors like dirt density (which affects weight and thus disposal fees), distance to the disposal site, type of equipment needed, and the specific fees charged by landfills. Another myth is that all soil is priced the same for disposal; wet, heavy soil often incurs higher fees.
Dirt Removal Cost Formula and Mathematical Explanation
The total cost of dirt removal is a sum of several key components. Our calculator uses the following comprehensive formula to provide an accurate estimate:
Total Cost = (Total Weight in Tons * Disposal Fee per Ton) + (Volume in yd³ * Transport Cost per yd³) + (Equipment Rental Cost per Day * Number of Project Days)
Variable Explanations:
- Volume of Dirt (V): The total amount of dirt to be removed, measured in cubic yards (yd³). This is the primary input determining the scale of the job.
- Dirt Density (D): The weight of the dirt per cubic yard. This is critical because disposal fees are typically charged by weight (tons). Different soil types (topsoil, clay, wet soil) have different densities.
- Disposal Fee per Ton (DF): The cost charged by the landfill or disposal facility for each ton of material they accept.
- Transport Cost per Cubic Yard (TC): The cost associated with hauling one cubic yard of dirt from the project site to the disposal facility. This often depends on distance and truck capacity.
- Equipment Rental Cost per Day (ER): The daily expense for machinery like excavators, loaders, or dump trucks needed for excavation and transport.
- Number of Project Days (PD): The estimated duration of the dirt removal operation, used to calculate total equipment rental costs.
Calculation Steps:
- Calculate Total Weight: Total Weight (tons) = Volume (yd³) * Dirt Density (lbs/yd³) / 2000 (lbs/ton).
- Calculate Total Disposal Cost: Total Disposal Cost = Total Weight (tons) * Disposal Fee per Ton ($/ton).
- Calculate Total Transport Cost: Total Transport Cost = Volume (yd³) * Transport Cost per yd³ ($/yd³).
- Calculate Total Equipment Cost: Total Equipment Cost = Equipment Rental Cost per Day ($/day) * Number of Project Days (days).
- Calculate Total Dirt Removal Cost: Sum of Total Disposal Cost, Total Transport Cost, and Total Equipment Cost.
Variables Table:
Dirt Removal Cost Variables
| Variable |
Meaning |
Unit |
Typical Range |
| Volume of Dirt |
Total amount of soil/debris to be removed. |
Cubic Yards (yd³) |
1 – 1000+ |
| Dirt Density |
Weight of dirt per unit volume. Varies by soil type and moisture. |
lbs/yd³ |
2500 – 3000 |
| Disposal Fee |
Cost charged by landfill/transfer station per ton of waste. |
$/Ton |
$20 – $100+ |
| Transport Cost |
Cost to haul one cubic yard of dirt to the disposal site. |
$/yd³ |
$50 – $150+ |
| Equipment Rental |
Daily cost for machinery like excavators, loaders, etc. |
$/Day |
$150 – $500+ |
| Project Days |
Estimated duration of the dirt removal operation. |
Days |
1 – 10+ |
Practical Examples (Real-World Use Cases)
Example 1: Small Backyard Landscaping Project
A homeowner is removing soil to create a new garden bed. They need to remove 15 cubic yards of topsoil. The topsoil is relatively light (2500 lbs/yd³). The local landfill charges $40 per ton for disposal, and hauling costs $60 per cubic yard. They estimate the work will take 2 days using a small excavator rented at $180 per day.
- Volume: 15 yd³
- Density: 2500 lbs/yd³
- Disposal Fee: $40/ton
- Transport Cost: $60/yd³
- Equipment Rental: $180/day
- Project Days: 2 days
Calculations:
- Total Weight = 15 yd³ * 2500 lbs/yd³ / 2000 lbs/ton = 18.75 tons
- Total Disposal Cost = 18.75 tons * $40/ton = $750
- Total Transport Cost = 15 yd³ * $60/yd³ = $900
- Total Equipment Cost = $180/day * 2 days = $360
- Total Estimated Cost = $750 + $900 + $360 = $2010
Interpretation: For this small landscaping job, the bulk of the cost comes from transportation, followed closely by disposal fees. Equipment rental is a smaller, fixed component.
Example 2: Medium-Sized Construction Site Excavation
A contractor is excavating for a foundation and needs to remove 200 cubic yards of heavy, wet clay soil. The landfill charges $70 per ton, and transport costs $90 per cubic yard. They will use a larger excavator rented at $350 per day and estimate the removal will take 5 days.
- Volume: 200 yd³
- Density: 3000 lbs/yd³
- Disposal Fee: $70/ton
- Transport Cost: $90/yd³
- Equipment Rental: $350/day
- Project Days: 5 days
Calculations:
- Total Weight = 200 yd³ * 3000 lbs/yd³ / 2000 lbs/ton = 300 tons
- Total Disposal Cost = 300 tons * $70/ton = $21,000
- Total Transport Cost = 200 yd³ * $90/yd³ = $18,000
- Total Equipment Cost = $350/day * 5 days = $1,750
- Total Estimated Cost = $21,000 + $18,000 + $1,750 = $40,750
Interpretation: For a larger construction project with heavy soil, both disposal fees and transport costs become significant expenses. The higher density of the soil directly increases the disposal cost due to the higher tonnage.
How to Use This Dirt Removal Calculator
Our Dirt Removal Cost Calculator is designed for simplicity and accuracy. Follow these steps to get your estimated cost:
- Enter Volume: Input the total cubic yards (yd³) of dirt you need to remove. Be as accurate as possible; measure the dimensions of the area to be excavated (Length x Width x Depth) and convert to cubic yards if necessary (e.g., cubic feet / 27).
- Select Dirt Density: Choose the option that best describes your soil type (light, medium, heavy). Wet soil is generally heavier.
- Input Disposal Fee: Find out the cost per ton charged by your local landfill or disposal site and enter it. This can vary significantly by location.
- Enter Transport Cost: Determine the cost per cubic yard for hauling the dirt. This often depends on the distance to the disposal site and the size of the trucks used.
- Estimate Equipment Rental: Input the daily rental cost for any machinery (excavator, loader, dump truck) you plan to use or will need.
- Specify Project Days: Estimate the number of days the dirt removal process will take.
- Click 'Calculate Cost': The calculator will instantly display your estimated total dirt removal cost, broken down into key components like disposal, transport, and equipment.
How to Read Results:
The primary result is the Total Estimated Cost. Below this, you'll see the breakdown: Total Weight (in tons), Total Disposal Fee, Total Transport Cost, and Total Equipment Cost. The chart visually represents this breakdown, making it easy to see which cost component is the largest.
Decision-Making Guidance:
Use the results to compare quotes from different contractors, adjust your project budget, or identify areas where costs might be reduced. For instance, if transport costs are high, consider if a closer disposal site is available. If equipment rental is a major factor, evaluate if you can complete the job faster or with less specialized machinery.
Key Factors That Affect Dirt Removal Costs
Several variables significantly influence the final price of dirt removal. Understanding these can help you get more accurate quotes and manage your budget effectively:
- Volume and Weight of Dirt: The sheer quantity of material is the most obvious factor. Larger volumes mean more hauling and disposal. Crucially, the weight (determined by density and moisture content) directly impacts disposal fees, which are often ton-based. Heavy, wet soil costs more to dispose of than dry, light soil.
- Distance to Disposal Site: Longer travel distances for trucks increase fuel consumption, driver time, and wear and tear on vehicles. This translates directly into higher transport costs per cubic yard.
- Disposal Fees (Landfill Rates): Each landfill or transfer station sets its own rates, typically per ton. These fees can vary dramatically based on location, local regulations, and the type of material being accepted. Some sites may also have surcharges for specific types of debris.
- Accessibility of the Site: Difficult-to-access sites may require specialized equipment or more time for loading and maneuvering, increasing labor and equipment rental costs. Tight spaces or steep slopes can complicate the process.
- Type of Equipment Required: The scale of the project dictates the machinery needed. Small jobs might use a skid steer, while large excavations require excavators and multiple dump trucks. Rental costs for heavy machinery can be substantial, especially for longer durations.
- Labor Costs: The cost of skilled operators and laborers is a significant component. This includes wages, benefits, and potentially overtime pay if the project runs longer than expected.
- Soil Type and Condition: As mentioned, density varies. Additionally, soil contaminated with hazardous materials, large rocks, or debris may incur special handling and disposal fees, significantly increasing costs.
- Permits and Regulations: Some projects may require permits for excavation or disposal, adding administrative costs. Local environmental regulations can also impact disposal options and associated fees.
Frequently Asked Questions (FAQ)
Q1: How accurate is this dirt removal cost calculator?
A: This calculator provides an estimate based on the inputs you provide. Actual costs can vary due to unforeseen site conditions, fluctuating market rates for disposal and transport, and specific contractor pricing. It's a valuable tool for budgeting but should be supplemented with actual quotes.
Q2: What is the average cost of dirt removal per cubic yard?
A: The average cost can range widely, typically from $50 to $150 per cubic yard, but this includes transport and disposal. Our calculator breaks this down further, showing that transport alone might be $50-$150/yd³, while disposal fees depend heavily on weight and landfill rates.
Q3: How do I measure the volume of dirt to remove?
A: Measure the length, width, and depth of the area to be excavated in feet. Multiply these three dimensions to get cubic feet. Then, divide the result by 27 to convert cubic feet to cubic yards (since 1 cubic yard = 27 cubic feet).
Q4: Can I reuse the dirt on my property instead of disposing of it?
A: Yes, if the dirt is clean and suitable for your landscaping needs (e.g., grading, filling), you can avoid disposal fees altogether. However, you'll still incur costs for excavation and moving the dirt on-site, which might require equipment rental and labor.
Q5: What if the dirt contains rocks or debris?
A: Large rocks or construction debris mixed with the soil can complicate removal and disposal. Some landfills may charge extra or refuse materials with excessive debris. You might need specialized equipment for breaking up rocks or separating materials, increasing costs.
Q6: How long does dirt removal typically take?
A: The duration depends heavily on the volume of dirt, site accessibility, and the equipment used. Small landscaping jobs might take a day or two, while large construction excavations can take weeks. Our calculator uses 'Project Days' to factor in equipment rental duration.
Q7: Should I get multiple quotes from contractors?
A: Absolutely. Getting at least 3 quotes from reputable contractors is highly recommended. Use the estimate from this calculator to understand the cost components and compare them against contractor bids. Ensure quotes detail all included services (transport, disposal, labor, equipment).
Q8: What are the environmental considerations for dirt removal?
A: Responsible dirt removal involves proper disposal to prevent soil erosion and contamination. Ensure your chosen disposal site adheres to environmental regulations. If the soil is suspected of contamination (e.g., from industrial sites), specialized testing and disposal procedures are required, which can be costly.
Related Tools and Internal Resources
var chartInstance = null; // Global variable to hold chart instance
function validateInput(id, min, max, errorMessageId, helperTextId) {
var input = document.getElementById(id);
var errorElement = document.getElementById(errorMessageId);
var helperTextElement = document.getElementById(helperTextId);
var value = parseFloat(input.value);
var isValid = true;
// Clear previous error and helper text
errorElement.innerText = ";
errorElement.classList.remove('visible');
if (helperTextElement) {
helperTextElement.style.display = 'block';
}
if (isNaN(value) || input.value.trim() === ") {
errorElement.innerText = 'This field is required.';
isValid = false;
} else if (value max) {
errorElement.innerText = 'Value cannot exceed ' + max + '.';
isValid = false;
}
if (!isValid) {
input.style.borderColor = 'var(–error-color)';
if (helperTextElement) {
helperTextElement.style.display = 'none';
}
errorElement.classList.add('visible');
} else {
input.style.borderColor = 'var(–border-color)';
}
return isValid;
}
function calculateDirtRemovalCost() {
// Clear previous errors
document.getElementById('volumeError').innerText = ";
document.getElementById('volumeError').classList.remove('visible');
document.getElementById('densityError').innerText = ";
document.getElementById('densityError').classList.remove('visible');
document.getElementById('disposalFeePerTonError').innerText = ";
document.getElementById('disposalFeePerTonError').classList.remove('visible');
document.getElementById('transportCostPerYardError').innerText = ";
document.getElementById('transportCostPerYardError').classList.remove('visible');
document.getElementById('equipmentRentalError').innerText = ";
document.getElementById('equipmentRentalError').classList.remove('visible');
document.getElementById('projectDaysError').innerText = ";
document.getElementById('projectDaysError').classList.remove('visible');
// Input values
var volume = parseFloat(document.getElementById('volume').value);
var density = parseFloat(document.getElementById('density').value);
var disposalFeePerTon = parseFloat(document.getElementById('disposalFeePerTon').value);
var transportCostPerYard = parseFloat(document.getElementById('transportCostPerYard').value);
var equipmentRental = parseFloat(document.getElementById('equipmentRental').value);
var projectDays = parseFloat(document.getElementById('projectDays').value);
// Validation
var allValid = true;
if (!validateInput('volume', 0, 10000, 'volumeError', 'volumeHelper')) allValid = false;
// Density is a select, no range validation needed here beyond ensuring a value is selected
if (!validateInput('disposalFeePerTon', 0, 1000, 'disposalFeePerTonError', 'disposalFeePerTonHelper')) allValid = false;
if (!validateInput('transportCostPerYard', 0, 500, 'transportCostPerYardError', 'transportCostPerYardHelper')) allValid = false;
if (!validateInput('equipmentRental', 0, 5000, 'equipmentRentalError', 'equipmentRentalHelper')) allValid = false;
if (!validateInput('projectDays', 0, 100, 'projectDaysError', 'projectDaysHelper')) allValid = false;
if (!allValid) {
document.getElementById('results').style.display = 'none';
return;
}
// Calculations
var totalWeightLbs = volume * density;
var totalWeightTons = totalWeightLbs / 2000;
var totalDisposalFee = totalWeightTons * disposalFeePerTon;
var totalTransportCost = volume * transportCostPerYard;
var totalEquipmentCost = equipmentRental * projectDays;
var totalCost = totalDisposalFee + totalTransportCost + totalEquipmentCost;
// Display results
document.getElementById('totalCost').innerText = '$' + totalCost.toFixed(2);
document.getElementById('totalWeight').innerText = 'Total Weight: ' + totalWeightTons.toFixed(2) + ' tons';
document.getElementById('totalDisposalFee').innerText = 'Total Disposal Fee: $' + totalDisposalFee.toFixed(2);
document.getElementById('totalTransportCost').innerText = 'Total Transport Cost: $' + totalTransportCost.toFixed(2);
document.getElementById('totalEquipmentCost').innerText = 'Total Equipment Cost: $' + totalEquipmentCost.toFixed(2);
document.getElementById('results').style.display = 'block';
// Update chart
updateChart(totalDisposalFee, totalTransportCost, totalEquipmentCost);
}
function resetCalculator() {
document.getElementById('volume').value = '50';
document.getElementById('density').value = '2700';
document.getElementById('disposalFeePerTon').value = '50';
document.getElementById('transportCostPerYard').value = '75';
document.getElementById('equipmentRental').value = '200';
document.getElementById('projectDays').value = '3';
// Clear errors and hide results
document.getElementById('volumeError').innerText = ";
document.getElementById('volumeError').classList.remove('visible');
document.getElementById('densityError').innerText = ";
document.getElementById('densityError').classList.remove('visible');
document.getElementById('disposalFeePerTonError').innerText = ";
document.getElementById('disposalFeePerTonError').classList.remove('visible');
document.getElementById('transportCostPerYardError').innerText = ";
document.getElementById('transportCostPerYardError').classList.remove('visible');
document.getElementById('equipmentRentalError').innerText = ";
document.getElementById('equipmentRentalError').classList.remove('visible');
document.getElementById('projectDaysError').innerText = ";
document.getElementById('projectDaysError').classList.remove('visible');
document.getElementById('results').style.display = 'none';
if (chartInstance) {
chartInstance.destroy();
chartInstance = null;
}
// Optionally re-run calculation with defaults
calculateDirtRemovalCost();
}
function copyResults() {
var resultsText = "Estimated Dirt Removal Cost:\n";
resultsText += "Total Cost: " + document.getElementById('totalCost').innerText + "\n";
resultsText += document.getElementById('totalWeight').innerText + "\n";
resultsText += document.getElementById('totalDisposalFee').innerText + "\n";
resultsText += document.getElementById('totalTransportCost').innerText + "\n";
resultsText += document.getElementById('totalEquipmentCost').innerText + "\n\n";
resultsText += "Key Assumptions:\n";
resultsText += "Volume: " + document.getElementById('volume').value + " yd³\n";
resultsText += "Density: " + document.getElementById('density').options[document.getElementById('density').selectedIndex].text.split(' – ')[0] + "\n";
resultsText += "Disposal Fee: $" + document.getElementById('disposalFeePerTon').value + "/ton\n";
resultsText += "Transport Cost: $" + document.getElementById('transportCostPerYard').value + "/yd³\n";
resultsText += "Equipment Rental: $" + document.getElementById('equipmentRental').value + "/day\n";
resultsText += "Project Days: " + document.getElementById('projectDays').value + " days\n";
var textArea = document.createElement("textarea");
textArea.value = resultsText;
document.body.appendChild(textArea);
textArea.select();
try {
var successful = document.execCommand('copy');
var msg = successful ? 'Results copied!' : 'Failed to copy results.';
console.log(msg);
// Optionally show a temporary message to the user
var tempAlert = document.createElement('div');
tempAlert.textContent = msg;
tempAlert.style.cssText = 'position: fixed; top: 10px; left: 50%; transform: translateX(-50%); background-color: var(–primary-color); color: white; padding: 10px 20px; border-radius: 5px; z-index: 1000;';
document.body.appendChild(tempAlert);
setTimeout(function() {
document.body.removeChild(tempAlert);
}, 2000);
} catch (err) {
console.error('Unable to copy results', err);
}
document.body.removeChild(textArea);
}
function updateChart(disposal, transport, equipment) {
var ctx = document.getElementById('costBreakdownChart').getContext('2d');
// Destroy previous chart instance if it exists
if (chartInstance) {
chartInstance.destroy();
}
// Create new chart instance
chartInstance = new Chart(ctx, {
type: 'bar',
data: {
labels: ['Disposal Fee', 'Transport Cost', 'Equipment Rental'],
datasets: [{
label: 'Cost Component ($)',
data: [disposal, transport, equipment],
backgroundColor: [
'rgba(0, 74, 153, 0.7)', // Primary color
'rgba(40, 167, 69, 0.7)', // Success color
'rgba(108, 117, 125, 0.7)' // Secondary color
],
borderColor: [
'rgba(0, 74, 153, 1)',
'rgba(40, 167, 69, 1)',
'rgba(108, 117, 125, 1)'
],
borderWidth: 1
}]
},
options: {
responsive: true,
maintainAspectRatio: false,
scales: {
y: {
beginAtZero: true,
ticks: {
// Format y-axis labels as currency
callback: function(value, index, values) {
return '$' + value.toLocaleString();
}
}
}
},
plugins: {
legend: {
display: false // Legend is handled by chartLegend div
},
tooltip: {
callbacks: {
label: function(context) {
var label = context.dataset.label || ";
if (label) {
label += ': ';
}
if (context.parsed.y !== null) {
label += new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD' }).format(context.parsed.y);
}
return label;
}
}
}
}
}
});
// Update legend
var legendHtml = '
';
chartInstance.data.datasets[0].backgroundColor.forEach((color, i) => {
legendHtml += '- ' + chartInstance.data.labels[i] + '
';
});
legendHtml += '
';
document.getElementById('chartLegend').innerHTML = legendHtml;
}
// Initial calculation on page load with default values
document.addEventListener('DOMContentLoaded', function() {
resetCalculator(); // Sets defaults and runs calculation
});