Easily calculate the weight per unit length (linear density) of materials. Essential for engineers, manufacturers, and material scientists.
Linear Density Calculator
Enter the name of the material (e.g., Copper Wire, Aluminum Bar).
Enter the total measured weight of the material sample.
Enter the total measured length of the material sample.
Kilograms (kg)
Grams (g)
Pounds (lb)
Ounces (oz)
Select the unit for the total weight.
Meters (m)
Centimeters (cm)
Feet (ft)
Inches (in)
Select the unit for the total length.
Calculation Results
–.–
Linear Density (Base Units): –.–
Equivalent Density (kg/m): –.–
Equivalent Density (lb/ft): –.–
Formula Used: Linear Density = Total Weight / Total Length
Material Density Comparison
A visual comparison of the calculated linear density against common materials.
Chart showing calculated and reference linear densities.
Calculation Details
Metric
Value
Unit
Material Name
N/A
–
Total Weight
N/A
N/A
Total Length
N/A
N/A
Calculated Linear Density
–.–
kg/m
Detailed breakdown of the input values and calculated linear density.
What is Weight Per Unit Length?
Weight per unit length, also known as linear density, is a fundamental physical property that quantifies how much mass an object has for each unit of its length. It's particularly useful when dealing with long, slender objects like wires, cables, rods, pipes, or even threads and ropes. Instead of considering the total weight and total volume (which would give volumetric density), linear density focuses solely on the distribution of mass along one dimension.
This metric is crucial in various engineering and manufacturing applications. For instance, knowing the weight per unit length of a specific type of wire helps determine the load capacity of overhead power lines, the required support structures for long cables, or the material cost per meter for production. In the textile industry, it's vital for understanding the quality and consistency of yarns and threads.
A common misconception is that weight per unit length is the same as volumetric density (mass per unit volume). While related (volumetric density is a factor in determining linear density for uniform cross-sections), they are distinct. Linear density is specific to one-dimensional measurements, whereas volumetric density applies to three-dimensional objects.
Who should use it: Engineers (mechanical, civil, electrical), material scientists, manufacturers, quality control inspectors, purchasing agents sourcing raw materials, architects, and anyone involved in projects where the mass distribution along a length is critical. This includes those working with structural beams, pipelines, cables, wires, textiles, and extruded materials.
Weight Per Unit Length Formula and Mathematical Explanation
The calculation of weight per unit length is straightforward. It involves dividing the total weight of a material sample by its corresponding total length. This gives us a measure of how heavy the material is for every meter, foot, or other unit of length it occupies.
The Core Formula
The fundamental formula for weight per unit length is:
Linear Density (ρL) = Total Weight (W) / Total Length (L)
Variable Explanations
Linear Density (ρL): This is the value we aim to calculate. It represents the mass per unit length.
Total Weight (W): This is the measured mass of the entire sample of the material.
Total Length (L): This is the measured length of the same sample of the material.
Mathematical Derivation and Units
The units of linear density depend directly on the units used for weight and length. If weight is measured in kilograms (kg) and length in meters (m), the linear density will be in kg/m. If weight is in pounds (lb) and length in feet (ft), the linear density will be in lb/ft. Our calculator allows you to specify these units and will provide results in common equivalents like kg/m and lb/ft for broader comparison.
Variables Table
Variable
Meaning
Unit
Typical Range / Notes
ρL
Linear Density
Mass/Length (e.g., kg/m, lb/ft)
Varies greatly by material and cross-section.
W
Total Weight (Mass)
Mass Units (kg, g, lb, oz)
Measured value for the sample. Must be positive.
L
Total Length
Length Units (m, cm, ft, in)
Measured value for the sample. Must be positive.
A
Cross-sectional Area
Area Units (m2, cm2, ft2, in2)
Calculated or known. Used to relate linear density to volumetric density.
ρV
Volumetric Density
Mass/Volume (e.g., kg/m3, lb/ft3)
Intrinsic property of the material.
The relationship between linear density (ρL) and volumetric density (ρV) for a uniform cross-sectional area (A) is: ρL = ρV * A.
Practical Examples (Real-World Use Cases)
Understanding weight per unit length is vital for practical applications across many industries. Here are a couple of examples:
Example 1: Electrical Wiring for a Construction Project
Scenario: An electrical contractor needs to determine the total weight of copper wire required for a large building. They have a spool containing 500 meters of 10 AWG copper wire. A sample of this wire is measured to have a total length of 10 meters and a total weight of 0.75 kg.
Inputs:
Material Name: Copper Wire (10 AWG)
Total Weight: 0.75 kg
Total Length: 10 m
Weight Unit: kg
Length Unit: m
Calculation:
Linear Density = 0.75 kg / 10 m = 0.075 kg/m
Equivalent Density (kg/m): 0.075 kg/m
Equivalent Density (lb/ft): Approximately 0.050 lb/ft
Interpretation: The linear density of this copper wire is 0.075 kg per meter. To find the total weight needed for the 500-meter spool, the contractor multiplies the linear density by the total length: 0.075 kg/m * 500 m = 37.5 kg. This helps in logistics, ordering materials, and planning the installation.
Example 2: Steel Tubing for a Framework
Scenario: An engineer is designing a lightweight structural framework using steel tubing. They need to know the weight per unit length to ensure the supports can handle the load. They have a sample of the steel tubing with a length of 6 feet and a measured weight of 15 pounds.
Inputs:
Material Name: Steel Tubing
Total Weight: 15 lb
Total Length: 6 ft
Weight Unit: lb
Length Unit: ft
Calculation:
Linear Density = 15 lb / 6 ft = 2.5 lb/ft
Equivalent Density (kg/m): Approximately 3.72 kg/m
Equivalent Density (lb/ft): 2.5 lb/ft
Interpretation: The steel tubing has a linear density of 2.5 pounds per foot. If the framework requires 100 feet of this tubing, the total weight contribution from the tubing would be 2.5 lb/ft * 100 ft = 250 pounds. This information is critical for structural analysis and load calculations, ensuring the framework's stability.
How to Use This Weight Per Unit Length Calculator
Our Weight Per Unit Length Calculator is designed for simplicity and accuracy. Follow these steps:
Enter Material Name: Input the name of the material you are analyzing (e.g., "Aluminum Rod," "Nylon Rope"). This helps in identifying the result.
Input Total Weight: Accurately measure and enter the total weight of your material sample. Ensure you know the unit of measurement.
Input Total Length: Accurately measure and enter the total length corresponding to the weighed sample. Ensure you know the unit of measurement.
Select Weight Unit: Choose the unit you used for the 'Total Weight' from the dropdown menu (e.g., kg, g, lb, oz).
Select Length Unit: Choose the unit you used for the 'Total Length' from the dropdown menu (e.g., m, cm, ft, in).
Click 'Calculate': Press the 'Calculate' button. The calculator will process your inputs.
How to Read Results
Main Result: This prominently displays the calculated linear density in a default base unit (e.g., kg/m), making it easy to see at a glance.
Intermediate Values: You'll see the linear density expressed in equivalent common units (e.g., kg/m and lb/ft) for easy comparison across different standards.
Formula Used: A reminder of the basic formula (Weight / Length) reinforces how the result was obtained.
Table: The detailed table breaks down your inputs and the final calculated density with their respective units.
Chart: The visual chart provides a comparison point against standard material densities.
Decision-Making Guidance
Use the results to:
Estimate Material Needs: Calculate the total weight of material required for a project based on its length.
Quality Control: Compare the calculated linear density of a sample against known standards for the material to ensure consistency and quality. Significant deviations may indicate manufacturing defects or incorrect material composition.
Cost Estimation: Determine the cost of materials per unit length for budgeting purposes.
Structural Analysis: In engineering, understand the load contribution of linear components.
Don't forget to use the 'Copy Results' button to easily transfer the data for reports or further analysis. If you need to start over, the 'Reset' button will clear the fields.
Key Factors That Affect Weight Per Unit Length Results
While the calculation itself is simple division, several factors influence the accuracy and interpretation of weight per unit length results:
Material Composition (Volumetric Density): The intrinsic density of the material (e.g., steel vs. aluminum vs. plastic) is the primary determinant. A denser material will inherently have a higher weight per unit length for the same dimensions. This is fundamental to understanding the inherent mass distribution.
Cross-Sectional Shape and Area: Even with the same material, the shape and size of the cross-section significantly impact linear density. A solid rod will have a higher linear density than a hollow tube of the same outer diameter made of the same material. The cross-sectional area is directly proportional to the linear density when volumetric density is constant.
Manufacturing Tolerances: Real-world manufacturing processes have variations. The diameter, wall thickness (for tubes), or shape of the material might not be perfectly uniform along its length. These variations can lead to slight discrepancies in measured total weight and length, affecting the calculated linear density. Consistent manufacturing leads to more predictable linear densities.
Measurement Accuracy: The precision of your weight and length measurements is paramount. Inaccurate scales or measuring tapes will directly result in inaccurate linear density calculations. For critical applications, using calibrated instruments is essential. Precise measurements are the bedrock of reliable data.
Presence of Impurities or Alloys: If the material is an alloy or contains impurities, its overall volumetric density might differ from the pure substance. This change in density will directly reflect in the weight per unit length. Understanding the exact composition is key for accurate material specification.
Environmental Factors (Less Common for Solids): While less significant for solid materials like rods or wires, for materials like ropes or fabrics, moisture absorption can slightly increase weight. Temperature can cause minor expansion or contraction in length, affecting precise measurements. However, for most structural materials, these effects are negligible compared to material composition and dimensions.
Unit System Consistency: Using inconsistent units (e.g., weight in grams but length in feet) without proper conversion will lead to nonsensical results. Always ensure your input units are correctly selected in the calculator or converted beforehand. Accurate unit handling prevents calculation errors.
Frequently Asked Questions (FAQ)
What is the difference between linear density and volumetric density?
Linear density (weight per unit length) measures mass along a single dimension (length), typically for objects like wires or rods. Volumetric density measures mass per unit volume (e.g., kg/m³), applicable to any three-dimensional object.
How do I get an accurate measurement for Total Weight and Total Length?
Use a calibrated scale for weight and a reliable measuring tape or caliper for length. Ensure the sample measured for length is the exact same piece weighed. For consistency, measure longer samples if possible.
Can I calculate the weight of a specific length if I know the weight per unit length?
Yes. Multiply the calculated weight per unit length (e.g., in kg/m) by the desired length (in meters) to find the total weight.
What if my material is not uniform in thickness?
If the material's cross-section varies significantly, the calculated weight per unit length will be an average. For highly variable materials, consider calculating density for different segments or using advanced methods.
Does temperature affect weight per unit length?
Temperature primarily affects length due to thermal expansion/contraction. While this can slightly alter the measured length and thus the calculated linear density, the actual mass of the material remains unchanged. For most practical purposes with solid materials, this effect is minor.
Can this calculator be used for non-standard shapes like I-beams?
Yes, provided you measure the total weight and total length of the beam accurately. The calculator provides the average linear density. For specific engineering calculations involving beams, tables of section properties (which include weight per foot or meter) are often used.
What are common units for weight per unit length?
Common units include kilograms per meter (kg/m), grams per centimeter (g/cm), pounds per foot (lb/ft), and pounds per inch (lb/in).
Why is weight per unit length important in electrical cables?
It determines the sag in overhead lines, the required strength of supporting structures, and the overall weight of cable runs in buildings or conduits, impacting installation logistics and safety.
Related Tools and Internal Resources
BMI Calculator – Understand your body mass index and its implications for health. (Related Keyword: BMI)
Loan Payment Calculator – Estimate your monthly loan payments based on principal, interest rate, and term. (Related Keyword: Loan Payment)
Compound Interest Calculator – See how your investments grow over time with compounding returns. (Related Keyword: Compound Interest)
Material Density Calculator – Calculate and compare the volumetric density of various substances. (Related Keyword: Material Density)
Road Slope Calculator – Determine the grade or slope percentage for roads and ramps. (Related Keyword: Road Slope)
Pipe Flow Calculator – Analyze fluid flow rates and pressure drops in pipes. (Related Keyword: Pipe Flow)
function getElement(id) {
return document.getElementById(id);
}
function validateInput(inputId, errorId, minValue = null, maxValue = null) {
var inputElement = getElement(inputId);
var errorElement = getElement(errorId);
var value = parseFloat(inputElement.value.trim());
errorElement.textContent = ""; // Clear previous error
if (isNaN(value)) {
errorElement.textContent = "Please enter a valid number.";
return false;
}
if (value <= 0) {
errorElement.textContent = "Value must be positive.";
return false;
}
if (minValue !== null && value maxValue) {
errorElement.textContent = "Value cannot be greater than " + maxValue + ".";
return false;
}
return true;
}
function convertToKgPerMeter(value, unit) {
var convertedValue = value;
switch (unit) {
case 'g/cm':
convertedValue = value * 1000; // g/cm to kg/m
break;
case 'kg/m':
convertedValue = value;
break;
case 'lb/ft':
convertedValue = value * 1.48816; // lb/ft to kg/m
break;
case 'lb/in':
convertedValue = value * 3.28084 * 12; // lb/in to lb/ft, then lb/ft to kg/m
break;
case 'oz/in':
convertedValue = value * (1/16) * 12 * 1.48816; // oz/in to lb/in, then lb/in to lb/ft, then lb/ft to kg/m
break;
case 'oz/ft':
convertedValue = value * (1/16) * 1.48816; // oz/ft to lb/ft, then lb/ft to kg/m
break;
// Add more conversions as needed
}
return convertedValue;
}
function convertToLbPerFoot(value, unit) {
var convertedValue = value;
switch (unit) {
case 'kg/m':
convertedValue = value / 1.48816; // kg/m to lb/ft
break;
case 'lb/ft':
convertedValue = value;
break;
case 'g/cm':
convertedValue = value / 100 * (1/1000) * 1.48816 * 100; // g/cm to kg/m, then kg/m to lb/ft
break;
case 'lb/in':
convertedValue = value * 12; // lb/in to lb/ft
break;
case 'oz/in':
convertedValue = value * (1/16) * 12; // oz/in to lb/in, then lb/in to lb/ft
break;
case 'oz/ft':
convertedValue = value * (1/16); // oz/ft to lb/ft
break;
// Add more conversions as needed
}
return convertedValue;
}
function calculateWeightPerUnitLength() {
var materialName = getElement('materialName').value.trim();
var totalWeight = getElement('totalWeight').value;
var totalLength = getElement('totalLength').value;
var weightUnit = getElement('weightUnit').value;
var lengthUnit = getElement('lengthUnit').value;
// Clear previous errors
getElement('totalWeightError').textContent = "";
getElement('totalLengthError').textContent = "";
// Validate inputs
var isWeightValid = validateInput('totalWeight', 'totalWeightError');
var isLengthValid = validateInput('totalLength', 'totalLengthError');
if (!isWeightValid || !isLengthValid) {
return;
}
var weight = parseFloat(totalWeight);
var length = parseFloat(totalLength);
// Calculate base linear density
var linearDensity = weight / length;
// Store original units and values for table
getElement('tableMaterialName').textContent = materialName || 'N/A';
getElement('tableTotalWeight').textContent = weight.toFixed(2);
getElement('tableWeightUnit').textContent = weightUnit;
getElement('tableTotalLength').textContent = length.toFixed(2);
getElement('tableLengthUnit').textContent = lengthUnit;
// Convert units for intermediate and main results
var baseUnit = weightUnit + '/' + lengthUnit;
var linearDensityKgPerMeter = convertToKgPerMeter(linearDensity, baseUnit);
var linearDensityLbPerFoot = convertToLbPerFoot(linearDensity, baseUnit);
// Determine units for display and table
var displayUnitKgPerMeter = 'kg/m';
var displayUnitLbPerFoot = 'lb/ft';
var tableDisplayUnit = 'kg/m'; // Default table unit
// Display main result
getElement('mainResult').textContent = linearDensityKgPerMeter.toFixed(3) + ' ' + displayUnitKgPerMeter;
// Display intermediate results
getElement('intermediateResult1').innerHTML = 'Linear Density (Base Units): ' + linearDensity.toFixed(3) + ' ' + baseUnit;
getElement('intermediateResult2').innerHTML = 'Equivalent Density (' + displayUnitKgPerMeter + '): ' + linearDensityKgPerMeter.toFixed(3) + ' ' + displayUnitKgPerMeter;
getElement('intermediateResult3').innerHTML = 'Equivalent Density (' + displayUnitLbPerFoot + '): ' + linearDensityLbPerFoot.toFixed(3) + ' ' + displayUnitLbPerFoot;
// Update table with calculated values
getElement('tableLinearDensity').textContent = linearDensityKgPerMeter.toFixed(3);
getElement('tableLinearDensityUnit').textContent = tableDisplayUnit;
// Update chart
updateChart(linearDensityKgPerMeter, linearDensityLbPerFoot);
}
function updateChart(densityKgPerMeter, densityLbPerFoot) {
var ctx = getElement('densityChart').getContext('2d');
// Sample data for common materials (kg/m)
var referenceData = [
{ name: 'Aluminum (Solid Rod)', kg_m: 24.5 }, // Approx. density 2700 kg/m^3, for a 10mm diameter rod (Area ~ 0.0000785 m^2)
{ name: 'Steel (Solid Rod)', kg_m: 61.7 }, // Approx. density 7850 kg/m^3, for a 10mm diameter rod
{ name: 'Copper (Wire)', kg_m: 5.6 }, // Approx. density 8960 kg/m^3, for a 1mm diameter wire (Area ~ 0.000000785 m^2)
{ name: 'Nylon (Rope)', kg_m: 10.0 }, // Example value, depends heavily on construction
{ name: 'Lead (Wire)', kg_m: 9.4 } // Approx. density 11340 kg/m^3, for a 1mm diameter wire
];
// Prepare data for chart
var labels = [materialName.value.trim() || 'Your Material'];
var yourDataKgM = [densityKgPerMeter];
var yourDataLbFt = [densityLbPerFoot];
var referenceLabels = [];
var referenceDataKgM = [];
var referenceDataLbFt = [];
referenceData.forEach(function(item) {
labels.push(item.name);
yourDataKgM.push(item.kg_m);
yourDataLbFt.push(item.kg_m * 1.48816); // Convert reference kg/m to lb/ft for comparison
referenceLabels.push(item.name);
referenceDataKgM.push(item.kg_m);
referenceDataLbFt.push(item.kg_m * 1.48816);
});
// Dynamic Y-axis scaling based on data range
var allValuesKgM = yourDataKgM.concat(referenceDataKgM);
var maxKgM = Math.max.apply(null, allValuesKgM) * 1.2; // Add some buffer
var minKgM = Math.min.apply(null, allValuesKgM) * 0.8;
if (minKgM < 0) minKgM = 0;
var allValuesLbFt = yourDataLbFt.concat(referenceDataLbFt);
var maxLbFt = Math.max.apply(null, allValuesLbFt) * 1.2;
var minLbFt = Math.min.apply(null, allValuesLbFt) * 0.8;
if (minLbFt < 0) minLbFt = 0;
// Decide which chart axis to primarily display based on user's result unit preference
var primaryAxis = 'kg/m'; // Default to kg/m
var activeKgMData = yourDataKgM;
var activeRefDataKgM = referenceDataKgM;
var activeKgMLabels = labels.slice(0, 1); // Only your material label
var activeRefKgMLabels = referenceLabels;
var activeLbFtData = yourDataLbFt;
var activeRefDataLbFt = referenceDataLbFt;
var activeLbFtLabels = labels.slice(0, 1);
var activeRefLbFtLabels = referenceLabels;
// Use kg/m as the primary axis for simplicity in this pure JS example
var yAxisMax = maxKgM;
var yAxisMin = minKgM;
var chartTitle = 'Weight Per Unit Length Comparison (kg/m)';
var chartData = {
labels: activeKgMLabels.concat(activeRefKgMLabels),
datasets: [{
label: 'Your Material (kg/m)',
data: activeKgMData,
backgroundColor: 'rgba(40, 167, 69, 0.6)',
borderColor: 'rgba(40, 167, 69, 1)',
borderWidth: 1,
fill: false,
tension: 0.1
}, {
label: 'Reference Materials (kg/m)',
data: activeRefDataKgM,
backgroundColor: 'rgba(0, 74, 153, 0.4)',
borderColor: 'rgba(0, 74, 153, 0.8)',
borderWidth: 1,
fill: false,
tension: 0.1
}]
};
// Destroy previous chart instance if it exists
if (window.densityChartInstance) {
window.densityChartInstance.destroy();
}
// Create new chart
window.densityChartInstance = new Chart(ctx, {
type: 'bar', // Use bar chart for better comparison of discrete values
data: chartData,
options: {
responsive: true,
maintainAspectRatio: true,
scales: {
y: {
beginAtZero: true,
title: {
display: true,
text: chartTitle
},
suggestedMax: yAxisMax,
suggestedMin: yAxisMin
},
x: {
title: {
display: true,
text: 'Material Type'
}
}
},
plugins: {
tooltip: {
callbacks: {
label: function(context) {
var label = context.dataset.label || '';
if (label) {
label += ': ';
}
if (context.parsed.y !== null) {
label += context.parsed.y.toFixed(3) + ' kg/m';
}
return label;
}
}
},
legend: {
position: 'top',
}
}
}
});
}
function copyResults() {
var mainResult = getElement('mainResult').textContent;
var intermediateResult1 = getElement('intermediateResult1').textContent.replace('', ").replace('', ");
var intermediateResult2 = getElement('intermediateResult2').textContent.replace('', ").replace('', ");
var intermediateResult3 = getElement('intermediateResult3').textContent.replace('', ").replace('', ");
var materialName = getElement('tableMaterialName').textContent;
var totalWeight = getElement('tableTotalWeight').textContent;
var weightUnit = getElement('tableWeightUnit').textContent;
var totalLength = getElement('tableTotalLength').textContent;
var lengthUnit = getElement('tableLengthUnit').textContent;
var copyText = "Weight Per Unit Length Calculation Results:\n\n";
copyText += "Material: " + materialName + "\n";
copyText += "Total Weight: " + totalWeight + " " + weightUnit + "\n";
copyText += "Total Length: " + totalLength + " " + lengthUnit + "\n\n";
copyText += "— Key Results —\n";
copyText += "Primary Result: " + mainResult + "\n";
copyText += intermediateResult1 + "\n";
copyText += intermediateResult2 + "\n";
copyText += intermediateResult3 + "\n\n";
copyText += "— Key Assumptions —\n";
copyText += "Formula Used: Linear Density = Total Weight / Total Length\n";
// Create a temporary textarea element
var textArea = document.createElement("textarea");
textArea.value = copyText;
textArea.style.position = "fixed"; // Avoid scrolling to bottom
textArea.style.left = "-9999px";
document.body.appendChild(textArea);
// Select and copy text
textArea.focus();
textArea.select();
try {
var successful = document.execCommand('copy');
var msg = successful ? 'Results copied to clipboard!' : 'Failed to copy results.';
console.log(msg);
// Optionally display a temporary message to the user
var statusDiv = document.createElement('div');
statusDiv.textContent = msg;
statusDiv.style.position = 'fixed';
statusDiv.style.bottom = '10px';
statusDiv.style.left = '50%';
statusDiv.style.transform = 'translateX(-50%)';
statusDiv.style.backgroundColor = '#004a99';
statusDiv.style.color = 'white';
statusDiv.style.padding = '10px 20px';
statusDiv.style.borderRadius = '5px';
statusDiv.style.zIndex = '1000';
document.body.appendChild(statusDiv);
setTimeout(function(){ document.body.removeChild(statusDiv); }, 2000);
} catch (err) {
console.error('Fallback: Oops, unable to copy', err);
}
// Remove temporary textarea
document.body.removeChild(textArea);
}
function resetCalculator() {
getElement('materialName').value = 'Steel Rod';
getElement('totalWeight').value = '100';
getElement('totalLength').value = '5';
getElement('weightUnit').value = 'kg';
getElement('lengthUnit').value = 'm';
// Clear errors
getElement('totalWeightError').textContent = "";
getElement('totalLengthError').textContent = "";
// Reset results
getElement('mainResult').textContent = '–.–';
getElement('intermediateResult1').innerHTML = 'Linear Density (Base Units): –.–';
getElement('intermediateResult2').innerHTML = 'Equivalent Density (kg/m): –.–';
getElement('intermediateResult3').innerHTML = 'Equivalent Density (lb/ft): –.–';
// Reset table
getElement('tableMaterialName').textContent = 'N/A';
getElement('tableTotalWeight').textContent = 'N/A';
getElement('tableWeightUnit').textContent = 'N/A';
getElement('tableTotalLength').textContent = 'N/A';
getElement('tableLengthUnit').textContent = 'N/A';
getElement('tableLinearDensity').textContent = '–.–';
getElement('tableLinearDensityUnit').textContent = 'kg/m';
// Reset chart data placeholder
updateChart(0, 0); // Call with dummy data to reset chart display
getElement('densityChart').getContext('2d').clearRect(0,0, getElement('densityChart').width, getElement('densityChart').height);
}
// Initial calculation on page load to populate with default values
document.addEventListener('DOMContentLoaded', function() {
// Load Chart.js library dynamically if needed, or ensure it's included in your theme/setup
// For this standalone HTML, we assume Chart.js is available via CDN or included elsewhere.
// If not, you'd need to add: in the
calculateWeightPerUnitLength(); // Perform initial calculation
});
// Add Chart.js script if not present globally
if (typeof Chart === 'undefined') {
var script = document.createElement('script');
script.src = 'https://cdn.jsdelivr.net/npm/chart.js';
document.head.appendChild(script);
}