Alcohol by Weight Calculation in Beer

Alcohol by Weight Calculator for Beer :root { –primary-color: #004a99; –success-color: #28a745; –background-color: #f8f9fa; –text-color: #333; –border-color: #ccc; –shadow-color: 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: 960px; margin: 20px auto; padding: 20px; background-color: #fff; border-radius: 8px; box-shadow: 0 2px 10px var(–shadow-color); } h1, h2, h3 { color: var(–primary-color); text-align: center; } h1 { margin-bottom: 20px; } .loan-calc-container { margin-bottom: 30px; padding: 20px; border: 1px solid var(–border-color); border-radius: 5px; } .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 select { width: calc(100% – 22px); padding: 10px; border: 1px solid var(–border-color); border-radius: 4px; box-sizing: border-box; font-size: 1rem; } .input-group small { display: block; margin-top: 5px; font-size: 0.85em; color: #6c757d; } .error-message { color: red; font-size: 0.8em; margin-top: 5px; display: none; } .results-container { margin-top: 30px; padding: 20px; background-color: var(–primary-color); color: white; border-radius: 5px; text-align: center; } .results-container h3 { color: white; margin-top: 0; } .primary-result { font-size: 2.5em; font-weight: bold; margin: 10px 0; } .intermediate-results div, .assumptions div { margin-bottom: 10px; font-size: 1.1em; } .btn-container { text-align: center; margin-top: 20px; } button { padding: 10px 20px; margin: 0 10px; border: none; border-radius: 4px; cursor: pointer; font-size: 1rem; transition: background-color 0.3s ease; } .btn-primary { background-color: var(–primary-color); color: white; } .btn-primary:hover { background-color: #003d7a; } .btn-success { background-color: var(–success-color); color: white; } .btn-success:hover { background-color: #218838; } .btn-secondary { background-color: #6c757d; color: white; } .btn-secondary:hover { background-color: #5a6268; } table { width: 100%; margin-top: 20px; border-collapse: collapse; box-shadow: 0 2px 5px var(–shadow-color); } th, td { padding: 12px 15px; text-align: left; border-bottom: 1px solid #ddd; } thead th { background-color: var(–primary-color); color: white; font-weight: bold; } tbody tr:nth-child(even) { background-color: #f2f2f2; } caption { font-size: 1.1em; font-weight: bold; margin-bottom: 10px; color: var(–primary-color); text-align: center; } #chartContainer { width: 100%; text-align: center; margin-top: 30px; } #chartContainer canvas { max-width: 100%; border: 1px solid var(–border-color); border-radius: 4px; } .article-section { margin-top: 40px; padding-top: 20px; border-top: 1px solid #eee; } .article-section h2 { text-align: left; margin-bottom: 15px; } .article-section h3 { text-align: left; margin-top: 20px; margin-bottom: 10px; color: #555; } .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; } .faq-question { font-weight: bold; color: var(–primary-color); cursor: pointer; } .faq-answer { margin-top: 5px; padding-left: 15px; border-left: 2px solid var(–primary-color); } .internal-links { margin-top: 30px; padding: 20px; background-color: #e9ecef; border-radius: 5px; } .internal-links h3 { text-align: left; margin-top: 0; } .internal-links ul { list-style: none; padding: 0; } .internal-links li { margin-bottom: 10px; } .internal-links a { color: var(–primary-color); text-decoration: none; font-weight: bold; } .internal-links a:hover { text-decoration: underline; } .internal-links p { font-size: 0.9em; color: #555; margin-top: 5px; } @media (max-width: 768px) { .container { margin: 10px; padding: 15px; } button { width: calc(50% – 20px); margin: 5px; } } .highlight-result { background-color: var(–success-color); color: white; padding: 15px; border-radius: 5px; text-align: center; margin-bottom: 20px; font-size: 1.8em; font-weight: bold; }

Alcohol by Weight (ABW) Calculator for Beer

Accurately calculate the Alcohol by Weight (ABW) of your beer. Essential for brewers and enthusiasts to understand their beer's true strength.

Beer Alcohol Content Calculator

Enter your beer's Original Gravity (OG) and Final Gravity (FG) to calculate Alcohol by Weight (ABW).

Measured in Specific Gravity (e.g., 1.050)
Please enter a valid Original Gravity (e.g., 1.000 to 1.150).
Measured in Specific Gravity (e.g., 1.010)
Please enter a valid Final Gravity (e.g., 0.995 to 1.030).

Your Beer's Alcohol Content

–.–%
Alcohol by Volume (ABV): –.–%
Apparent Attenuation: –.–%
Gravity Difference (OG – FG): -.—
Key Assumptions:
Water density assumed at 1.000 g/mL at room temperature.

Formula Explained

Alcohol by Weight (ABW) is calculated by determining the difference between the original and final specific gravity of the beer. This difference, representing the sugars fermented into alcohol and CO2, is converted into a percentage of the total weight of the beer. We first calculate Alcohol by Volume (ABV) using a common formula and then convert ABV to ABW by accounting for the density difference between alcohol and water.

Gravity Difference = Original Gravity – Final Gravity

ABV ≈ (OG – FG) * 131.25

ABW = ABV * (Density of Alcohol / Density of Beer)

Since the density of beer is very close to the density of water (approx. 1 g/mL), and the density of ethanol is approx. 0.789 g/mL, we approximate the conversion:

ABW ≈ ABV * 0.789

Gravity Readings Comparison
Reading Type Value (Specific Gravity) Description
Original Gravity (OG) The specific gravity of the wort before fermentation begins. Indicates the amount of fermentable sugars.
Final Gravity (FG) The specific gravity of the beer after fermentation is complete. Indicates remaining sugars and produced alcohol.
Calculated ABW –.–% The alcohol content expressed as a percentage of the beer's total weight.
Calculated ABV –.–% The alcohol content expressed as a percentage of the beer's total volume.
Apparent Attenuation –.–% The percentage of sugars fermented out of the original amount.
Gravity vs. Alcohol Content Progression

What is Alcohol by Weight (ABW) in Beer?

Alcohol by Weight (ABW) is a measure of the alcohol content in a beverage, specifically beer in this context, expressed as a percentage of the total weight of the liquid. Unlike Alcohol by Volume (ABV), which measures alcohol as a percentage of the liquid's volume, ABW considers how much each unit of alcohol contributes to the overall mass. For brewers, understanding ABW provides a different perspective on the potency and composition of their beer, often complementing ABV readings. While ABV is more commonly used on beer labels and in general discussion due to its simpler calculation and relation to volume, ABW can be important for specific brewing contexts, especially when dealing with density and mass balance. For instance, in some regulatory environments or for precise recipe formulation, ABW might be a required metric.

Who Should Use It: Homebrewers seeking detailed analysis of their beer's composition, craft brewers involved in quality control or specific recipe development, and beer enthusiasts interested in the technical aspects of brewing will find ABW calculations useful. It's particularly relevant for understanding how different ingredient choices might affect the final density and alcohol distribution by mass.

Common Misconceptions: A frequent misconception is that ABW and ABV are interchangeable or directly proportional without considering density. Another is that a higher ABW necessarily means a "stronger" tasting beer, which isn't always true as perceived strength is influenced by many factors beyond alcohol percentage, such as hop bitterness, malt sweetness, and carbonation. It's also sometimes confused with Proof, which is simply double the ABV in the US system.

Alcohol by Weight (ABW) Formula and Mathematical Explanation

The calculation of Alcohol by Weight (ABW) in beer typically involves a two-step process: first, determining the Alcohol by Volume (ABV), and then converting that to ABW using density considerations.

Step 1: Calculate Alcohol by Volume (ABV)

A common and practical formula to estimate ABV from specific gravity readings is:

ABV (%) = (Original Gravity – Final Gravity) × 131.25

Where:

  • Original Gravity (OG): The specific gravity of the wort before fermentation.
  • Final Gravity (FG): The specific gravity of the beer after fermentation.

This formula approximates the amount of sugar fermented into alcohol and CO2, translating it into a percentage of the total liquid volume. The factor 131.25 is an empirical constant derived from experimental data relating gravity loss to alcohol production.

Step 2: Convert ABV to Alcohol by Weight (ABW)

To convert ABV to ABW, we need to consider the densities of alcohol (ethanol) and the beer itself. The density of pure ethanol at standard room temperature (e.g., 20°C or 68°F) is approximately 0.789 g/mL. The density of beer is very close to the density of water, which is approximately 1.000 g/mL. Therefore, the ABW can be approximated as:

ABW (%) = ABV (%) × (Density of Ethanol / Density of Beer)

Using the approximate densities:

ABW (%) ≈ ABV (%) × (0.789 g/mL / 1.000 g/mL)

ABW (%) ≈ ABV (%) × 0.789

Variable Explanations Table

Variable Meaning Unit Typical Range
Original Gravity (OG) Density of wort before fermentation relative to water. Specific Gravity (unitless) 1.000 – 1.150
Final Gravity (FG) Density of beer after fermentation relative to water. Specific Gravity (unitless) 0.995 – 1.030
ABV Alcohol by Volume percentage. % (v/v) 2% – 12% (for most beers)
ABW Alcohol by Weight percentage. % (w/w) 1.5% – 9.5% (for most beers)
Apparent Attenuation Percentage of original sugars fermented. % 65% – 85%

Practical Examples (Real-World Use Cases)

Understanding alcohol by weight calculation is crucial for brewers. Here are a couple of practical examples:

Example 1: A Standard Pale Ale

A homebrewer is making a Pale Ale. They measure the Original Gravity (OG) of their wort as 1.052 and after fermentation, the Final Gravity (FG) is measured at 1.012.

  • Calculate Gravity Difference: 1.052 – 1.012 = 0.040
  • Calculate ABV: 0.040 × 131.25 = 5.25% ABV
  • Calculate ABW: 5.25% × 0.789 ≈ 4.14% ABW

Interpretation: This Pale Ale has approximately 5.25% Alcohol by Volume and 4.14% Alcohol by Weight. The ABW is lower than ABV because alcohol is less dense than water. This result is typical for many sessionable or standard ales.

Example 2: A High-Gravity Imperial Stout

A craft brewer is working on a new Imperial Stout recipe. Their initial gravity reading is 1.090 (OG), and after a long fermentation, the final gravity settles at 1.022 (FG).

  • Calculate Gravity Difference: 1.090 – 1.022 = 0.068
  • Calculate ABV: 0.068 × 131.25 = 8.93% ABV
  • Calculate ABW: 8.93% × 0.789 ≈ 7.05% ABW

Interpretation: This Imperial Stout is a strong beer, boasting approximately 8.93% Alcohol by Volume and 7.05% Alcohol by Weight. The significant difference between OG and FG indicates a high degree of fermentation, resulting in a potent beer. The ABW provides a clear measure of the alcohol's contribution to the beer's overall mass.

How to Use This Alcohol by Weight Calculator

Our Alcohol by Weight (ABW) calculator is designed for simplicity and accuracy. Follow these steps to get your beer's ABW:

  1. Measure Original Gravity (OG): Before fermentation begins, use a hydrometer to measure the specific gravity of your wort. Enter this value (e.g., 1.050) into the "Original Gravity (OG)" field.
  2. Measure Final Gravity (FG): Once fermentation is complete (typically when gravity readings stabilize over a few days), measure the specific gravity of your beer. Enter this value (e.g., 1.010) into the "Final Gravity (FG)" field.
  3. Click "Calculate ABW": The calculator will instantly process your inputs.

How to Read Results:

  • The primary result, displayed prominently, is your beer's Alcohol by Weight (ABW) percentage.
  • You will also see the Alcohol by Volume (ABV) percentage, the Apparent Attenuation (how much sugar was consumed by yeast), and the Gravity Difference.
  • The table provides a summary of key gravity readings and calculated values.
  • The chart visually represents the relationship between gravity and alcohol content.

Decision-Making Guidance: Use these results to understand your beer's strength, adjust recipes for future batches, ensure consistency, or meet specific labeling requirements. For instance, if your ABW is significantly lower than intended, it might indicate under-pitching yeast, incorrect temperature control, or insufficient fermentable sugars.

Key Factors That Affect Alcohol by Weight Results

While the primary calculation relies on gravity readings, several underlying factors influence the outcome and interpretation of ABW and related metrics in brewing:

  1. Yeast Health and Strain: The type of yeast used and its health significantly impact fermentation efficiency. A healthy, appropriate yeast strain will consume more sugars, leading to a lower FG, higher ABV, and consequently, a different ABW compared to an unhealthy or unsuitable strain.
  2. Fermentation Temperature: Yeast activity is highly temperature-dependent. Temperatures too high can stress yeast, producing off-flavors and potentially incomplete fermentation. Temperatures too low can slow fermentation significantly. Both scenarios affect the final FG and thus the ABW.
  3. Mash Temperature and Grain Bill: The temperatures used during the mash determine the types of sugars produced (e.g., more fermentable vs. less fermentable). A mash focused on producing highly fermentable sugars (often at lower temperatures) will result in a lower FG and higher alcohol content by both volume and weight. The choice of grains (malted barley, adjuncts) also dictates the potential sugar profile.
  4. Water Chemistry: While not directly in the ABW formula, water ions can influence mash efficiency and yeast health. Proper water adjustments can lead to better enzymatic activity during the mash, yielding more fermentable sugars and thus impacting the final alcohol content.
  5. Oxygenation: Adequate dissolved oxygen is crucial for yeast health and initial growth during the lag phase of fermentation. Insufficient oxygen can lead to sluggish fermentation and a lower final attenuation, affecting FG and ABW.
  6. Time: Fermentation takes time. Rushing the process or stopping it prematurely will result in a higher FG, lower ABV, and lower ABW. Patience ensures yeast has sufficient time to ferment the available sugars.
  7. Carbonation: While CO2 produced during fermentation is accounted for in the gravity difference calculation (as it affects density), the final carbonation level itself doesn't directly alter the ABW percentage calculation based on OG and FG. However, the dissolved CO2 does slightly lower the beer's density.
  8. Sugar Profile Complexity: Beers with a high proportion of complex sugars (dextrins) that yeast cannot ferment will naturally have a higher FG, leading to lower apparent attenuation and lower calculated alcohol percentages (both ABV and ABW), contributing to body and mouthfeel rather than alcohol strength.

Frequently Asked Questions (FAQ)

Q1: Is Alcohol by Weight (ABW) higher or lower than Alcohol by Volume (ABV)?
ABW is generally lower than ABV because alcohol (ethanol) is less dense than water. When you consider the weight percentage, the lighter alcohol contributes less to the total weight than it does to the total volume.
Q2: Why do some sources use different formulas for ABV?
The formula ABV = (OG – FG) * 131.25 is an approximation. More complex formulas exist that account for the density changes caused by dissolved CO2 and the non-linear relationship between gravity and alcohol content. However, the 131.25 factor provides a very close estimate for most practical brewing purposes.
Q3: Can I use a hydrometer and calculator for all types of beer?
Yes, the calculation method using OG and FG is applicable to virtually all fermented beverages, including lagers, ales, stouts, porters, and even meads and ciders. The key is accurate gravity readings.
Q4: What is "Apparent Attenuation"?
Apparent Attenuation is the percentage of the original sugars that the yeast has consumed and converted into alcohol and CO2. It's calculated as ((OG – FG) / (OG – 1.000)) * 100%. It gives an indication of how thoroughly the yeast fermented the wort.
Q5: Does ABW affect the taste of beer?
Directly, ABW itself doesn't impart a specific taste, but the underlying alcohol content (whether measured by weight or volume) contributes to the "warmth" or perceived strength of the beer. High alcohol content can also suppress other flavors or contribute to sweetness if fermentation is incomplete.
Q6: How accurate are these calculations?
The accuracy depends heavily on the precision of your hydrometer and the accuracy of your gravity readings. Temperature correction for hydrometer readings is also important for maximum accuracy. The formulas used are widely accepted approximations in the brewing community.
Q7: What is the typical ABW range for different beer styles?
Light beers might have ABW around 2-3%, standard ales 4-5%, and high-gravity beers like Imperial Stouts can reach 7-10% ABW or even higher. This is a rough guide, as specific recipes and fermentation profiles vary widely.
Q8: Should I focus on ABW or ABV for my brewing?
ABV is the more commonly used and understood metric for labeling and general discussion. ABW can be useful for specific density-related calculations or regulatory purposes. Most brewers track and aim for a target ABV.
function calculateABW() { var ogInput = document.getElementById("originalGravity"); var fgInput = document.getElementById("finalGravity"); var ogError = document.getElementById("ogError"); var fgError = document.getElementById("fgError"); var resultsSection = document.getElementById("resultsSection"); var og = parseFloat(ogInput.value); var fg = parseFloat(fgInput.value); // Reset previous errors ogError.style.display = "none"; fgError.style.display = "none"; ogInput.style.borderColor = "var(–border-color)"; fgInput.style.borderColor = "var(–border-color)"; var isValid = true; // Input validation if (isNaN(og) || og 1.150) { ogError.style.display = "block"; ogInput.style.borderColor = "red"; isValid = false; } if (isNaN(fg) || fg 1.030) { fgError.style.display = "block"; fgInput.style.borderColor = "red"; isValid = false; } if (fg >= og) { fgError.textContent = "Final Gravity must be less than Original Gravity."; fgError.style.display = "block"; fgInput.style.borderColor = "red"; isValid = false; } if (!isValid) { resultsSection.style.display = "none"; return; } var gravityDifference = og – fg; var abv = gravityDifference * 131.25; var abw = abv * 0.789; // Approximate conversion using densities var apparentAttenuation = ((og – fg) / (og – 1.000)) * 100; // Format results var formattedABW = abw.toFixed(2); var formattedABV = abv.toFixed(2); var formattedAttenuation = apparentAttenuation.toFixed(2); var formattedGravityDifference = gravityDifference.toFixed(3); // Display results document.getElementById("mainResult").innerText = formattedABW + "%"; document.getElementById("abvResult").innerText = "Alcohol by Volume (ABV): " + formattedABV + "%"; document.getElementById("attenuationResult").innerText = "Apparent Attenuation: " + formattedAttenuation + "%"; document.getElementById("gravityDifference").innerText = "Gravity Difference (OG – FG): " + formattedGravityDifference; // Update table document.getElementById("tableOG").innerText = og.toFixed(3); document.getElementById("tableFG").innerText = fg.toFixed(3); document.getElementById("tableABW").innerText = formattedABW + "%"; document.getElementById("tableABV").innerText = formattedABV + "%"; document.getElementById("tableAttenuation").innerText = formattedAttenuation + "%"; resultsSection.style.display = "block"; updateChart(og, fg, abw, abv); } function resetCalculator() { document.getElementById("originalGravity").value = "1.050"; document.getElementById("finalGravity").value = "1.010"; document.getElementById("ogError").style.display = "none"; document.getElementById("fgError").style.display = "none"; document.getElementById("originalGravity").style.borderColor = "var(–border-color)"; document.getElementById("finalGravity").style.borderColor = "var(–border-color)"; document.getElementById("resultsSection").style.display = "none"; } function copyResults() { var mainResult = document.getElementById("mainResult").innerText; var abvResult = document.getElementById("abvResult").innerText; var attenuationResult = document.getElementById("attenuationResult").innerText; var gravityDiffResult = document.getElementById("gravityDifference").innerText; var assumptions = "Key Assumptions: Water density assumed at 1.000 g/mL at room temperature."; var copyText = "— Beer Alcohol Calculation Results —\n"; copyText += "ABW: " + mainResult + "\n"; copyText += abvResult + "\n"; copyText += attenuationResult + "\n"; copyText += gravityDiffResult + "\n"; copyText += assumptions + "\n\n"; copyText += "— Table Summary —" + "\n"; copyText += "Original Gravity (OG): " + document.getElementById("tableOG").innerText + "\n"; copyText += "Final Gravity (FG): " + document.getElementById("tableFG").innerText + "\n"; copyText += "Calculated ABW: " + document.getElementById("tableABW").innerText + "\n"; copyText += "Calculated ABV: " + document.getElementById("tableABV").innerText + "\n"; copyText += "Apparent Attenuation: " + document.getElementById("tableAttenuation").innerText + "\n"; var textArea = document.createElement("textarea"); textArea.value = copyText; textArea.style.position = "fixed"; textArea.style.left = "-9999px"; document.body.appendChild(textArea); textArea.select(); try { var successful = document.execCommand('copy'); var msg = successful ? 'Results copied to clipboard!' : 'Failed to copy results.'; alert(msg); } catch (err) { alert('Oops, unable to copy'); } document.body.removeChild(textArea); } // Charting Functionality var myChart; // Declare globally to manage chart instance function updateChart(og, fg, abw, abv) { var ctx = document.getElementById('gravityABWChart').getContext('2d'); // Destroy previous chart instance if it exists if (myChart) { myChart.destroy(); } // Define gravity points for the x-axis, relative to water (1.000) // We'll use a simplified range that covers typical brewing values var gravityAxisMax = 1.100; // Max gravity to display var gravityAxisMin = 0.990; // Min gravity to display var gravityRange = gravityAxisMax – gravityAxisMin; // Scale gravity points for the canvas width var scaleGravity = function(gravity) { return ((gravity – gravityAxisMin) / gravityRange) * ctx.canvas.width; }; // Scale alcohol percentage for the y-axis var alcoholAxisMax = 12; // Max ABV to display var alcoholAxisMin = 0; // Min ABV to display var alcoholRange = alcoholAxisMax – alcoholAxisMin; var scaleAlcohol = function(alcohol) { // Invert the scale for canvas (0,0 is top-left) return ctx.canvas.height – (((alcohol – alcoholAxisMin) / alcoholRange) * ctx.canvas.height); }; var abwAxisMax = 9.5; // Max ABW to display var abwAxisMin = 0; // Min ABW to display var abwRange = abwAxisMax – abwAxisMin; var scaleABW = function(abw) { return ctx.canvas.height – (((abw – abwAxisMin) / abwRange) * ctx.canvas.height); }; myChart = new Chart(ctx, { type: 'line', data: { labels: ['Water', 'OG', 'FG'], // Labels for key points datasets: [ { label: 'Specific Gravity', data: [ {x: scaleGravity(1.000), y: ctx.canvas.height * 0.9}, // Base line for water {x: scaleGravity(og), y: ctx.canvas.height * 0.9}, // OG point on gravity line {x: scaleGravity(fg), y: ctx.canvas.height * 0.9} // FG point on gravity line ], borderColor: 'rgba(54, 162, 235, 1)', // Blue for gravity backgroundColor: 'rgba(54, 162, 235, 0.2)', fill: false, tension: 0.1, pointRadius: 6, borderWidth: 2 }, { label: 'ABV (%)', data: [ {x: scaleGravity(1.000), y: scaleAlcohol(0)}, // Start at 0% ABV for water {x: scaleGravity(og), y: scaleAlcohol(0)}, // 0% ABV at OG {x: scaleGravity(fg), y: scaleAlcohol(abv)} // ABV at FG ], borderColor: 'rgba(255, 99, 132, 1)', // Red for ABV backgroundColor: 'rgba(255, 99, 132, 0.2)', fill: false, tension: 0.1, pointRadius: 6, borderWidth: 2 }, { label: 'ABW (%)', data: [ {x: scaleGravity(1.000), y: scaleABW(0)}, // Start at 0% ABW for water {x: scaleGravity(og), y: scaleABW(0)}, // 0% ABW at OG {x: scaleGravity(fg), y: scaleABW(abw)} // ABW at FG ], borderColor: 'rgba(75, 192, 192, 1)', // Green for ABW backgroundColor: 'rgba(75, 192, 192, 0.2)', fill: false, tension: 0.1, pointRadius: 6, borderWidth: 2 } ] }, options: { responsive: true, maintainAspectRatio: true, aspectRatio: 2, // Make chart wider than tall scales: { x: { type: 'custom_linear', // Use custom scale for gravity position: 'bottom', title: { display: true, text: 'Specific Gravity (relative to water)', color: 'var(–primary-color)' }, ticks: { callback: function(value, index, ticks) { // Convert scaled x-coordinate back to gravity value for display var gravity = gravityAxisMin + (value / ctx.canvas.width) * gravityRange; // Format ticks to show specific gravity if (gravity >= 0.990 && gravity = 0 && alcohol <= alcoholAxisMax) { // Display ticks for both ABV and ABW ranges clearly return alcohol.toFixed(1) + '%'; } return ''; }, stepSize: 2, // Show ticks every 2% maxTicksLimit: 6 }, min: 0, // Canvas coordinate min max: ctx.canvas.height // Canvas coordinate max } }, plugins: { legend: { display: true, position: 'top' }, tooltip: { callbacks: { label: function(context) { var label = context.dataset.label || ''; if (label) { label += ': '; } // Display relevant data based on context if (context.dataset.label === 'Specific Gravity') { // Reconstruct gravity value from scaled x var gravity = gravityAxisMin + (context.parsed.x / ctx.canvas.width) * gravityRange; label += gravity.toFixed(3); } else { // ABV or ABW value label += context.parsed.y.toFixed(2) + '%'; } return label; } } } }, layout: { padding: { left: 20, right: 20, top: 20, bottom: 20 } } } }); // Custom scale registration for gravity (x-axis) Chart.register( { id: 'custom_linear', beforeUpdate: function(chart) { var xAxis = chart.options.scales.x; if (xAxis.type === 'custom_linear') { xAxis.type = 'linear'; // Use standard linear scale xAxis.min = 0; // Canvas coordinate minimum xAxis.max = chart.canvas.width; // Canvas coordinate maximum } } }); // Custom scale registration for inverted alcohol (y-axis) Chart.register( { id: 'custom_linear_inverted', beforeUpdate: function(chart) { var yAxis = chart.options.scales.y; if (yAxis.type === 'custom_linear_inverted') { yAxis.type = 'linear'; // Use standard linear scale yAxis.min = 0; // Canvas coordinate minimum yAxis.max = chart.canvas.height; // Canvas coordinate maximum yAxis.reverse = true; // Invert the scale } } }); } // Initial calculation on load if default values are present document.addEventListener('DOMContentLoaded', function() { calculateABW(); // Activate FAQ toggles 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'; } }); }); });

Leave a Comment