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.jsonConversion rate
ErrorBarChartErrorBarTabledefaultErrorBarChartLabels- +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
import { ChartCard } from "@/components/sheenui/charts/chart-parts/chart-card";
import { ErrorBarChart } from "@/components/sheenui/charts/error-bar-chart";
import { errorBarLegend, type ErrorBarItem } from "@/components/sheenui/charts/error-bar-chart/model";
import { ErrorBarTable } from "@/components/sheenui/charts/error-bar-chart/table";
// Package build (after the first npm release, or a packed tarball): import { ChartCard, ErrorBarChart, ErrorBarTable, errorBarLegend, type ErrorBarItem } from "@sheenui/theme";
const variants: ErrorBarItem[] = [
{ label: "Control", value: 12.4, low: 11.1, high: 13.7 },
{ label: "Variant A", value: 14.2, low: 12.9, high: 15.5 },
{ label: "Variant B", value: 13.1, low: 11.4, high: 14.8 },
];
export function Example() {
return (
<ChartCard
title="Conversion rate"
legend={errorBarLegend("Rate", "95% interval")}
table={<ErrorBarTable data={variants} valueLabel="Rate (%)" intervalLabel="95% interval" caption="Conversion rate by variant" />}
>
<ErrorBarChart
data={variants}
variant="bar"
valueLabel="Conversion rate (%)"
aria-label="Conversion rate by variant, with 95% intervals"
/>
</ChartCard>
);
}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
import { ChartCard } from "@/components/sheenui/charts/chart-parts/chart-card";
import { ErrorBarChart } from "@/components/sheenui/charts/error-bar-chart";
import { type ErrorBarItem } from "@/components/sheenui/charts/error-bar-chart/model";
import { ErrorBarTable } from "@/components/sheenui/charts/error-bar-chart/table";
// Package build (after the first npm release, or a packed tarball): import { ChartCard, ErrorBarChart, ErrorBarTable, type ErrorBarItem } from "@sheenui/theme";
const effects: ErrorBarItem[] = [
{ label: "New onboarding", value: 4.2, low: 1.8, high: 6.6 },
{ label: "Social proof", value: 0.8, low: -1.5, high: 3.1 },
{ label: "Price anchor", value: -3.4, low: -6.2, high: -0.6 },
];
export function Example() {
return (
<ChartCard
title="Change in sign-ups"
table={<ErrorBarTable data={effects} valueLabel="Change (pp)" caption="Change in sign-up rate" />}
>
<ErrorBarChart
data={effects}
variant="point"
reference={{ value: 0, label: "No change" }}
valueLabel="Change in sign-up rate (percentage points)"
aria-label="Change in sign-up rate by experiment"
/>
</ChartCard>
);
}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.tsxcomponents/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.tslib/{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
import { ChartCard } from "@/components/sheenui/charts/chart-parts/chart-card";
import { ErrorBarChart } from "@/components/sheenui/charts/error-bar-chart";
import { type ErrorBarItem } from "@/components/sheenui/charts/error-bar-chart/model";
import { ErrorBarTable } from "@/components/sheenui/charts/error-bar-chart/table";
// Package build (after the first npm release, or a packed tarball): import { ChartCard, ErrorBarChart, ErrorBarTable, type ErrorBarItem } from "@sheenui/theme";
const forecast: ErrorBarItem[] = [
{ label: "Jan", value: 120, low: 114, high: 126 },
{ label: "Feb", value: 133, low: 125, high: 141 },
{ label: "Mar", value: 146, low: 136, high: 156 },
{ label: "Apr", value: 151, low: 139, high: 163 },
];
export function Example() {
return (
<ChartCard
title="Revenue forecast"
table={<ErrorBarTable data={forecast} valueLabel="Revenue ($K)" caption="Revenue forecast" />}
>
<ErrorBarChart data={forecast} variant="band" height={260} aria-label="Revenue forecast with a confidence band" />
</ChartCard>
);
}Props
ErrorBarChartLabels keys and English defaults (9)
ErrorBarTable props
Keyboard
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
Related pages
48 charts pages in all: browse them on Charts.
By Lokendra Singh Rathore (GitHub, opens in a new tab). Published , updated .