Skip to content
GitHub (opens in a new tab)

Bar

Compare magnitudes across categories with vertical or horizontal bars.

stableOrganismcontracts/barchart.json

Preview

Chart

Bar

Compare magnitudes across categories. Bar length ranks close values. Not a Chart cousin.

Master

Vertical bars with a grid. One ranked comparison.

Revenue by region

Close values, the right job for this form

Usage

Use BarChart when readers need to rank magnitudes. Vertical for time or ordered categories, horizontal when labels run long. Hover a bar to read it.

Do's

  • Ranking values at a glance
  • Grouped comparisons with categories plus series

Don'ts

<BarChart
  title="Revenue by region"
  description="Close values, the right job for this form"
  data={[
    { label: 'Region A', value: 2610 },
    { label: 'Region B', value: 2540 },
  ]}
/>

When to use

  • Ranking values at a glance
  • Grouped comparisons with categories plus series

When not to use

  • Part-to-whole share — use PieChart
  • Change over time — use LineChart

What an agent reads

import { BarChart } from "agentic-ds-kit";
must
  • Title on figure when provided
  • The plot svg is role=group named by the title when it holds focusable points (role=img only when empty)
  • Hover reads the category
  • Legend highlight emphasises one series
  • Bars expose category and value in accessible names
  • Table view keeps values readable
  • Repeated category labels each keep their own bar and table row
  • Too many categories for the width: the plot scrolls sideways in a focusable, named region with the value axis pinned
  • animate is decorative only: no motion under prefers-reduced-motion, and hover, focus, legend and table work during the entrance
defaults
  • orientation vertical
  • showGrid true
  • showTable true
  • height 240
  • emptyLabel No data for this range
  • isLoading false
  • animate false
stops if
  • Do not invent chart container cousins
  • Do not use it for a short ranked list where each row shows its value or links to its item — use BarList
  • Do not draw bars and a line on one chart from two charts — use ComboChart
  • Do not plot two numeric measures per item (x against y) — use ScatterChart
  • Do not use raw hex
  • Do not wrap a chart in a Card only to get a header button — pass actions

From contracts/barchart.json: must is the a11y requirements, defaults the prop defaults, stops if the doNot rules where the agent asks instead of inventing a cousin.

Props

NameTypeRequiredDefaultNotes
dataarrayNo—single-series flat array
categoriesarrayNo——
seriesarrayNo——
titlestringNo——
descriptionstringNo——
orientationvertical | horizontalNovertical—
showGridbooleanNotrue—
showTablebooleanNotrue—
heightnumberNo240—
emptyLabelstringNoNo data for this range—
isLoadingbooleanNofalse—
tickIntervalnumberNo—draw every Nth axis label; with neither tickInterval nor formatLabel, labels thin automatically only when they would overlap
formatLabelfunctionNo—(category, index) => string for the painted axis label; return '' to hide one (turns off automatic thinning). Table and accessible names keep the raw category
animatebooleanNofalseBars grow from the zero line (negative values grow downward, horizontal bars sideways) with a short stagger when they first appear. Runs when the chart mounts; changing data on a mounted chart does not replay it. To replay (e.g. one chart per Tabs panel, or a range switcher), give the chart a key that changes with the data. Off under prefers-reduced-motion
actionsslotNo—Kit Buttons in the chart header, before the Table toggle, like an icon-only Ask. ghost sm reads quietest. Setting it draws the frame even with no title.
  • Component
    →

    Pie

    Part-to-whole share for a handful of segments, as a donut or solid pie.

  • Component
    →

    Line

    Change and progress over ordered samples as a line or area chart.

  • Component
    →

    UsageMeter

    Plan usage or AI credits against a limit: total, usage by category, daily bars toned against the cap, and a warning near the limit.