Basic Error Bar Plot in MUI X Charts (JavaScript)

The same plot in 14 other libraries — JavaScript: Chart.js, D3.js, Apache ECharts, Highcharts; Python: Altair, Bokeh, lets-plot, Matplotlib, Plotly, plotnine, Pygal, Seaborn; R: ggplot2; Julia: Makie.jl. Compare all 15 side by side: Basic Error Bar Plot in Python, R, Julia and JavaScript.

An error bar plot displays data points with associated uncertainty or variability represented by bars extending above and below (or left and right of) each point. Error bars commonly represent standard deviation, standard error, confidence intervals, or min/max ranges. This visualization is essential for communicating the reliability and precision of measurements or statistical estimates.

Basic Error Bar Plot rendered with MUI X Charts

Renders

JavaScript source (MUI X Charts)

// anyplot.ai
// errorbar-basic: Basic Error Bar Plot
// Library: muix 9.16.0 | JavaScript 22.23.3
// Quality: 86/100 | Updated: 2026-10-24

import * as React from "react";
import { ChartsContainer } from "@mui/x-charts/ChartsContainer";
import { ChartsXAxis } from "@mui/x-charts/ChartsXAxis";
import { ChartsYAxis } from "@mui/x-charts/ChartsYAxis";
import { ChartsGrid } from "@mui/x-charts/ChartsGrid";
import { useXScale, useYScale } from "@mui/x-charts/hooks";

const t = window.ANYPLOT_TOKENS;

// Constants
const FONT = "-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif";
const TITLE = "errorbar-basic · javascript · muix · anyplot.ai";
const Y_PAD_SHARE = 0.14;
const CAP_BAND_SHARE = 0.22;
const MARKER_RADIUS = 10;
const SERIES_COLOR = t.palette[0];

// Columns: set these to your data's column names
const CONDITION = "Growth condition"; // role: x
const ELONGATION = "Mean stem elongation (cm / week)"; // role: y
const ERROR = "Standard deviation (cm / week)"; // role: error

// Data: replace this block with your own records
const data = [
  { [CONDITION]: "Control", [ELONGATION]: 4.2, [ERROR]: 0.5 },
  { [CONDITION]: "Low Temp", [ELONGATION]: 2.8, [ERROR]: 0.7 },
  { [CONDITION]: "High Temp", [ELONGATION]: 3.1, [ERROR]: 0.6 },
  { [CONDITION]: "Low pH", [ELONGATION]: 2.4, [ERROR]: 0.8 },
  { [CONDITION]: "High pH", [ELONGATION]: 3.6, [ERROR]: 0.5 },
  { [CONDITION]: "Drought", [ELONGATION]: 1.9, [ERROR]: 0.6 },
  { [CONDITION]: "Flood", [ELONGATION]: 2.2, [ERROR]: 0.9 },
];

// Plot: reads only data and the constants above
const categories = data.map((r) => String(r[CONDITION]));
const means = data.map((r) => Number(r[ELONGATION]));
const errors = data.map((r) => Number(r[ERROR]));

const lowerBounds = data.map((r) => Number(r[ELONGATION]) - Number(r[ERROR]));
const upperBounds = data.map((r) => Number(r[ELONGATION]) + Number(r[ERROR]));
const rawMin = Math.min(...lowerBounds);
const rawMax = Math.max(...upperBounds);
const span = rawMax - rawMin;
const yMin = rawMin - span * Y_PAD_SHARE;
const yMax = rawMax + span * Y_PAD_SHARE;
const SUBTITLE = `Error bars: ± ${ERROR} · ${categories.length} ${CONDITION}s`;

function ErrorBars() {
  const xScale = useXScale("x") as any;
  const yScale = useYScale("y") as any;

  const bw = xScale.bandwidth();
  const cap = Math.min(20, Math.round(bw * CAP_BAND_SHARE));

  return (
    <g>
      {categories.map((cond, i) => {
        const cx = xScale(cond) + bw / 2;
        const yTop = yScale(means[i] + errors[i]);
        const yBot = yScale(means[i] - errors[i]);
        const yMid = yScale(means[i]);
        return (
          <g key={cond}>
            <line
              x1={cx}
              y1={yTop}
              x2={cx}
              y2={yBot}
              stroke={SERIES_COLOR}
              strokeWidth={3}
              strokeLinecap="round"
            />
            <line
              x1={cx - cap}
              y1={yTop}
              x2={cx + cap}
              y2={yTop}
              stroke={SERIES_COLOR}
              strokeWidth={3}
              strokeLinecap="round"
            />
            <line
              x1={cx - cap}
              y1={yBot}
              x2={cx + cap}
              y2={yBot}
              stroke={SERIES_COLOR}
              strokeWidth={3}
              strokeLinecap="round"
            />
            <circle
              cx={cx}
              cy={yMid}
              r={MARKER_RADIUS}
              fill={SERIES_COLOR}
              stroke={t.pageBg}
              strokeWidth={3}
            />
          </g>
        );
      })}
    </g>
  );
}

export default function Chart() {
  const W = window.ANYPLOT_SIZE.width;
  const H = window.ANYPLOT_SIZE.height;
  const headerH = 84;
  const chartH = H - headerH;

  return (
    <div
      style={{
        width: W,
        height: H,
        backgroundColor: t.pageBg,
        display: "flex",
        flexDirection: "column",
        fontFamily: FONT,
      }}
    >
      <div
        style={{
          height: headerH,
          display: "flex",
          flexDirection: "column",
          alignItems: "center",
          justifyContent: "center",
          gap: 6,
        }}
      >
        <div style={{ fontSize: 22, fontWeight: 600, color: t.ink }}>{TITLE}</div>
        <div style={{ fontSize: 15, color: t.inkSoft }}>{SUBTITLE}</div>
      </div>

      <ChartsContainer
        width={W}
        height={chartH}
        skipAnimation
        series={[]}
        xAxis={[
          {
            id: "x",
            scaleType: "band",
            data: categories,
            height: 60,
            label: CONDITION,
            labelStyle: { fontSize: 16, fontWeight: 600, fill: t.ink, fontFamily: FONT },
            tickLabelStyle: { fontSize: 14, fill: t.inkSoft, fontFamily: FONT },
          },
        ]}
        yAxis={[
          {
            id: "y",
            scaleType: "linear",
            min: yMin,
            max: yMax,
            width: 88,
            label: ELONGATION,
            labelStyle: { fontSize: 16, fontWeight: 600, fill: t.ink, fontFamily: FONT },
            tickLabelStyle: { fontSize: 14, fill: t.inkSoft, fontFamily: FONT },
          },
        ]}
        margin={{ top: 20, bottom: 20, left: 24, right: 48 }}
      >
        <ChartsGrid horizontal />
        <ErrorBars />
        <ChartsXAxis axisId="x" />
        <ChartsYAxis axisId="y" />
      </ChartsContainer>
    </div>
  );
}

Retrieve this implementation

Runnable source as JSON, for any HTTP client: https://api.anyplot.ai/specs/errorbar-basic/muix/code. Any spec id and library id listed in llms-full.txt fit the same URL shape; every URL below is complete and callable.

{
  "spec_id": "errorbar-basic",
  "language": "javascript",
  "library": "muix",
  "page": "https://anyplot.ai/errorbar-basic/javascript/muix",
  "hub": "https://anyplot.ai/errorbar-basic",
  "code_json": "https://api.anyplot.ai/specs/errorbar-basic/muix/code",
  "spec_json": "https://api.anyplot.ai/specs/errorbar-basic",
  "render_light_png": "https://storage.googleapis.com/anyplot-images/plots/errorbar-basic/javascript/muix/plot-light.png",
  "render_dark_png": "https://storage.googleapis.com/anyplot-images/plots/errorbar-basic/javascript/muix/plot-dark.png",
  "interactive_light_html": "https://storage.googleapis.com/anyplot-images/plots/errorbar-basic/javascript/muix/plot-light.html",
  "interactive_dark_html": "https://storage.googleapis.com/anyplot-images/plots/errorbar-basic/javascript/muix/plot-dark.html",
  "quality_score": 86.0,
  "license": "MIT",
  "guide": "https://anyplot.ai/llms.txt"
}

Part of Basic Error Bar Plot on anyplot.ai.

Other implementations