🪟 Windows TippsThe Gemini desktop app is now available for Windows(11.09.2026 um 17:06 Uhr)
⚠️ Malware / Trojaner / VirenWindows 11 just dropped the tool ransomware abused, Microsoft says don’t restore WMIC(10.09.2026 um 20:11 Uhr)
⚠️ Malware / Trojaner / VirenVorsicht: Android-Malware verschlüsselt Ihre Handys und nimmt heimlich Fotos auf(11.09.2026 um 09:35 Uhr)
🕵️ SicherheitslückenMicrosoft geht endlich eines der nervigsten Probleme von Windows 11 an(11.09.2026 um 11:58 Uhr)
💾 IT Security ToolsSysinternals Suite(11.09.2026 um 12:00 Uhr)
🕵️ SicherheitslückenDefender 0-Day ShieldBreak (CVE-2026-69414) nicht sauber gepatcht - BornCity(11.09.2026 um 12:52 Uhr)
🔧 AI Nachrichten Stealing AI Reasoning Traces(08.09.2026 um 12:20 Uhr)
🪟 Windows TippsThe Gemini desktop app is now available for Windows(11.09.2026 um 17:06 Uhr)
⚠️ Malware / Trojaner / VirenWindows 11 just dropped the tool ransomware abused, Microsoft says don’t restore WMIC(10.09.2026 um 20:11 Uhr)
⚠️ Malware / Trojaner / VirenVorsicht: Android-Malware verschlüsselt Ihre Handys und nimmt heimlich Fotos auf(11.09.2026 um 09:35 Uhr)
🕵️ SicherheitslückenMicrosoft geht endlich eines der nervigsten Probleme von Windows 11 an(11.09.2026 um 11:58 Uhr)
💾 IT Security ToolsSysinternals Suite(11.09.2026 um 12:00 Uhr)
🕵️ SicherheitslückenDefender 0-Day ShieldBreak (CVE-2026-69414) nicht sauber gepatcht - BornCity(11.09.2026 um 12:52 Uhr)
🔧 AI Nachrichten Stealing AI Reasoning Traces(08.09.2026 um 12:20 Uhr)

🔧 Programmierung 🕛 vor 2 Monaten 7 Min Lesezeit
0

Build a Box Plot Calculator in Pure JavaScript — No Libraries Needed

↗ Quelle (dev.to)
🗣️ Stimme:
📑 Inhaltsübersicht




Build a Box Plot Calculator in Pure JavaScript — No Libraries Needed



A box plot (or box-and-whisker plot) is one of the most powerful tools in exploratory data analysis. In one compact graphic, it reveals the median, spread, skewness, and outliers of a dataset — all from just five numbers.



In this tutorial, I'll walk through building a complete box plot calculator from scratch using vanilla JavaScript and SVG. No D3, no Chart.js, no dependencies. By the end, you'll understand:




  • How to compute quartiles the right way

  • How to detect outliers with Tukey's fences

  • How to render a box plot as SVG

  • Why all of this matters for real-world data analysis



If you want to skip the code and use a ready-made tool, I built too.




Try it now → , you can switch between these thresholds in real time.









4. Rendering as SVG



Now for the fun part — turning numbers into a chart. Here's the core SVG rendering logic:




CODE
function renderBoxPlot(stats, width = 500, height = 200) {
const { min, q1, median, q3, max, outliers } = stats;

// Scale setup
const padL = 50, padR = 30, padT = 20, padB = 40;
const plotW = width - padL - padR;
const plotH = height - padT - padB;

const dataMin = Math.min(min, ...outliers);
const dataMax = Math.max(max, ...outliers);
const range = dataMax - dataMin || 1;
const paddedMin = dataMin - range * 0.08;
const paddedMax = dataMax + range * 0.08;
const paddedRange = paddedMax - paddedMin;

// Map data value → SVG x-coordinate
const sx = (v) => padL + plotW * ((v - paddedMin) / paddedRange);

const boxY = padT + plotH * 0.2;
const boxH = plotH * 0.6;
const yc = padT + plotH / 2;
const color = "#2563eb";

return `
<svg viewBox="0 0
${width} ${height}" xmlns="http://www.w3.org/2000/svg">
<!-- Axis -->
<line x1="
${padL}" y1="${padT + plotH}"
x2="
${padL + plotW}" y2="${padT + plotH}"
stroke="#d1d5db" stroke-width="0.5"/>

<!-- Left whisker -->
<line x1="
${sx(min)}" y1="${yc - boxH / 4}"
x2="
${sx(min)}" y2="${yc + boxH / 4}"
stroke="
${color}" stroke-width="1.5" stroke-linecap="round"/>
<line x1="
${sx(min)}" y1="${yc}"
x2="
${sx(q1)}" y2="${yc}"
stroke="
${color}" stroke-width="0.5" stroke-dasharray="3 3"/>

<!-- Box (Q1 to Q3) -->
<rect x="
${sx(q1)}" y="${boxY}"
width="
${sx(q3) - sx(q1)}" height="${boxH}"
fill="
${color}" opacity="0.15" stroke="${color}" stroke-width="1.5" rx="2"/>

<!-- Median line -->
<line x1="
${sx(median)}" y1="${boxY}"
x2="
${sx(median)}" y2="${boxY + boxH}"
stroke="
${color}" stroke-width="2" stroke-linecap="round"/>

<!-- Right whisker -->
<line x1="
${sx(q3)}" y1="${yc}"
x2="
${sx(max)}" y2="${yc}"
stroke="
${color}" stroke-width="0.5" stroke-dasharray="3 3"/>
<line x1="
${sx(max)}" y1="${yc - boxH / 4}"
x2="
${sx(max)}" y2="${yc + boxH / 4}"
stroke="
${color}" stroke-width="1.5" stroke-linecap="round"/>

<!-- Outlier dots -->
${outliers.map(o => `<circle cx="${sx(o)}" cy="${yc}" r="4"
fill="none" stroke="
${color}" stroke-width="1.5"/>`).join("")}
</svg>
`
;
}






The key insight: SVG is just XML. A box plot is just <line>, <rect>, and <circle> elements — no canvas, no external libraries.









5. Putting It All Together






CODE
// Example: exam scores from two classes
const dataA = [72, 85, 78, 90, 65, 88, 76, 92, 70, 84, 79, 86, 74, 91, 68, 83, 77, 89, 71, 95];
const dataB = [60, 62, 58, 70, 55, 68, 72, 64, 68, 61, 75, 66, 53, 77, 69, 71, 59, 63, 67, 74];

const statsA = calculateStats(dataA);
const statsB = calculateStats(dataB);

console.log("Class A — Median:", statsA.median, "IQR:", statsA.iqr);
console.log("Class B — Median:", statsB.median, "IQR:", statsB.iqr);
console.log("Outliers in A:", statsA.outliers);
console.log("Outliers in B:", statsB.outliers);

document.getElementById("chart-a").innerHTML = renderBoxPlot(statsA);
document.getElementById("chart-b").innerHTML = renderBoxPlot(statsB);






Side-by-side comparison instantly reveals:




  • Class A has a higher median and wider spread

  • No outliers in either class

  • Class B scores are more tightly clustered



This kind of insight takes seconds with a box plot — and pages of text to describe otherwise.









From Demo to Production



Building a working box plot is straightforward. Building a great one takes more:





  • Multi-dataset comparison — stacking boxes vertically with independent colors


  • Notched boxes — 95% confidence intervals around the median (McGill-Tukey-Kramer method)


  • Jitter scatter overlays — showing every raw data point without overlap


  • Responsive scaling — charts that look sharp at any screen size


  • Export to PNG/SVG — for papers, presentations, and reports


  • AI-powered analysis — automatic insights about distribution shape and skewness



I built so you can see exactly how every calculation and SVG element is constructed.




Make your first box plot → a try.

Vollständiger Original-Bericht
Ausführliche Details, Code-Beispiele & Hersteller-Stellungnahme auf dev.to.
↗ Original-Artikel auf dev.to lesen
Wie bewertest du diesen Beitrag?
1 Klick Feedback
Teilen mit Netzwerk & Team:

Community-Analysen & Experten-Meinungen 0

Verfasse deine eigene Analyse, teile Workarounds oder diskutiere diesen Vorfall im Blog.
Noch keine Community-Analyse verfasst. Markiere einen Textabschnitt oder klicke oben auf Eigene Analyse verfassen“!
Community Pulse: Relevanz-Einschätzung
1 Klick Experten-Votum
🔴 Akute Relevanz 0%
🟡 In Evaluierung 0%
🟢 Keine Auswirkung 0%
Spannende Innovation 0%
Verwandte Story-Cluster & Quellen (Vektor-KI)
Port 8095 Engine
1 Quelle
Text Watermarking in Python: Catch Whoever Copies Your Writing
1 Quelle
Why Most Multi-Agent Systems Fail Even When Evaluation Passes
1 Quelle
A Beginner’s Guide to World Models
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Build a Box Plot Calculator in Pure JavaScript — No Libraries Needed

Thematisch verwandte Begriffe: Build, Plot, Calculator, Pure · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...