Skip to content

Error Bar Chart for React

A React error bar chart that draws an estimate with its confidence interval as bars, points or a shaded band. Pass data as readonly ErrorBarItem[]: one item per mark, { label, value, low, high }.

npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/error-bar-chart.json

Conversion rate

Use the up and down arrow keys to read each item, Home and End for the first and last.

  • ErrorBarChart
  • ErrorBarTable
  • defaultErrorBarChartLabels
  • +1 more

Bars and points

Conversion rate per variant with a 95% interval. Bars grow from the baseline and the whiskers draw outwards; switch to points when the baseline is not meaningful.

Conversion rate

By variant, with a 95% interval

  • Rate
  • 95% interval

Effects against a reference line

variant="point" with a reference line at 0: an effect whose whisker crosses the line is not clearly different from "no change". Values and ends are printed in the tooltip and the table.

Change in sign-ups

Percentage points against the control, with 95% intervals

Files to copy

13 folders · 30 files · 4 packages
From theme/src/
  • components/charts/{error-bar-chart.tsx, bar-flip.tsx, chart-export-menu.tsx, chart-export.ts, chart-figure.tsx, chart-fit.tsx, chart-icons.tsx, chart-parts.tsx, chart-patterns.tsx, chart-pointer.tsx, chart-tip.tsx, chart-utils.ts, heatmap.tsx}
  • components/charts/chart-parts/
  • components/charts/error-bar-chart/
  • components/charts/heatmap/
  • components/drawer/parts/sheet.tsx
  • components/kbd/
  • components/menu/
  • components/skeleton/
  • components/status-icons/
  • hooks/{use-controllable.ts, use-direction.ts, use-intersection.ts, use-latest.ts, use-media-query.ts, use-preferences.ts}
  • motion/tokens.ts
  • lib/{cn.ts, csv.ts, form.ts, glide-highlight.tsx, heading.ts, math.ts, popup-a11y.ts, popup-motion.ts, warn-once.ts}
  • styles/
shadcn CLI
npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/error-bar-chart.jsonRegistry item: error-bar-chart. The styles need the Tailwind v4 glass UI setup.
Packages
pnpm add @base-ui/react clsx motion tailwind-merge

Next.js: samples here pass functions (formatters, seriesLegend, a dashboard's load), so put them in a file that starts with "use client".

Confidence band

variant="band": a line through the estimates with the interval shaded around it, widening as the forecast looks further ahead. The band fades in, the line draws on.

Revenue forecast

In thousands of dollars, 95% band

Props

PropTypeDefaultDescription
data (required)readonly ErrorBarItem[]NoneOne item per mark: { label, value, low, high, color? }.
variant"bar" | "point" | "band""bar""bar": bars from the baseline with a whisker; "point": a dot with a whisker (for estimates and effects); "band": a line with a shaded confidence band over ordered categories (a time series).
baselinenumber0Where the bars start (variant "bar").
reference{ value: number; label: string; }NoneA reference line, e.g. { value: 0, label: "No effect" }.
showValuesbooleantruePrint each estimate next to its mark (not on a band).
colorChartColor1Sets the palette slot (1–8) used for the whole chart.
patternsbooleantrue when item colours > 3Tell items of different colours apart without colour: hatched bars, and different marker shapes for points and bands (the first colour stays solid and round).
heightnumber300Height of the plot in px. Bars and points grow with the number of rows; a band chart uses it as is.
valueLabelstringNoneNames the value axis.
intervalLabelstringlabels.intervalNameNames the interval in the legend, readout and table (e.g. "95% CI").
format((n: number) => string)formatCompact in localeFormats a value for the labels, tooltips and data table: takes the number, returns the text shown.
localestring"en"Locale of the default number format.
emptyStateReactNodeNoneShown when there is nothing to plot.
labelsPartial<ErrorBarChartLabels>defaultErrorBarChartLabelsEvery other string, for translation: labels={{ roleDescription: "…" }}; omitted keys keep the English of defaultErrorBarChartLabels. All 9 keys of ErrorBarChartLabels are listed in the key table under the props table.
aria-label (required)stringNoneNames the chart for assistive tech (required).
classNamestringNoneAdds extra classes to the outer element.
ErrorBarChartLabels keys and English defaults (9)
Pass any key in labels; the rest keep the defaults of defaultErrorBarChartLabels.
KeyEnglish default
roleDescriptionerror bar chart
instructions({ vertical }) => `Use the ${vertical ? "left and right" : "up and down"} arrow keys to read each item, Hom...
valueEstimate
interval(low, high) => `${low} to ${high}`
intervalNameInterval
itemItem
lowerLower
upperUpper
noDataNo data

ErrorBarTable props

PropTypeDefaultDescription
data (required)readonly ErrorBarItem[]NoneOne item per mark: { label, value, low, high, color? }.
format((n: number) => string)formatCompact in localeFormats a value for the labels, tooltips and data table: takes the number, returns the text shown.
labelsPartial<ErrorBarChartLabels>defaultErrorBarChartLabelsEvery other string, for translation: labels={{ roleDescription: "…" }}; omitted keys keep the English of defaultErrorBarChartLabels. All 9 keys of ErrorBarChartLabels are listed in the key table under the props table.
localestring"en"Locale of the default number format.
valueLabelstringNoneNames the value axis.
intervalLabelstringlabels.intervalNameNames the interval in the legend, readout and table (e.g. "95% CI").
captionstringNoneHidden caption that names the table for screen readers.
classNamestringNoneAdds extra classes to the outer element.

Keyboard

KeysAction
TabFocus the chart. It is one tab stop; the arrow keys then read it.
↑/↓Bars and points: move between items.
←/→Band: move between points (flipped in right-to-left text).
Home/EndJump to the first / last item.
EscapeClear the reading.

Accessibility

  • The chart is a focusable figure named by its aria-label (the chart title), with the keyboard hint as its description and, inside a ChartCard with a table view, aria-details pointing at that table. Moving through it announces each item, its estimate and both ends of its interval.
  • The interval is a drawn whisker with end caps (or a dashed-edged band), a shape rather than a colour, and its ends are printed as numbers in the tooltip and in ErrorBarTable.
  • Reduced motion: bars, whiskers and the band appear at once and data changes jump instead of gliding.

All exports on this page

  • ErrorBarChart — An error bar chart: an estimate for each item with the interval around it, drawn as a whisker.
  • ErrorBarTable — Every item with its estimate and the lower and upper end of its interval.
  • defaultErrorBarChartLabels — The built-in English strings of ErrorBarChart; spread it into your own labels and change what you need.

When to use the error bar chart

  • Use it for A/B test results, survey estimates and model scores, where how sure a number is matters as much as the number: each bar or dot carries a whisker from the low to the high end of its interval.
  • Use variant="point" with a reference line for effect sizes in the forest-plot style, so any whisker that crosses the line reads as no clear difference.
  • Use variant="band" for a forecast or a measurement over time: a line of estimates with the confidence interval shaded around it, widening as the future gets less certain.
  • Skip it when you have the raw observations, where a Box plot or Beeswarm shows the whole distribution, or when every value is exact and there is no interval to draw.
  • Pair it with ChartCard, errorBarLegend and ErrorBarTable so the card gets a legend, a Chart / Table switch and a text version of every interval.

Frequently asked questions

48 charts pages in all: browse them on Charts.

By Lokendra Singh Rathore (GitHub, opens in a new tab). Published , updated .