Comparison · Basic

Bar chart

Grouped, stacked, 100% and horizontal bars, with optional lines on the same axis.

Open in playground
Use when
Comparing sizes across categories precisely
Avoid when
The flow over time is the point (a line works better)

Try it

16

Bar chart

Revenue by quarter (100M KRW)
  • Domestic
  • Overseas
Bar chartBar chart. 4 categories, 2 series (Domestic, Overseas). 4218482451335541
Bar chart data
Q1 · Domestic42
Q1 · Overseas18
Q2 · Domestic48
Q2 · Overseas24
Q3 · Domestic51
Q3 · Overseas33
Q4 · Domestic55
Q4 · Overseas41
Overseas grows its share every quarterBasic

Hover over the chart, or Tab in and use the arrow keys to move between items. The numbers are sample data.

Variants

Named looks for this chart. Each one is the example above with a few options or fields changed. The CLI (ztd-charts example bar --variant <id>) and the MCP server know the same names.

Grouped

Revenue by quarter (100M KRW)
  • Domestic
  • Overseas
Sample data

100% stacked

Revenue by quarter (100M KRW)
  • Domestic
  • Overseas
Sample data

Horizontal

Revenue by quarter (100M KRW)
  • Domestic
  • Overseas
Sample data

Code

BarChart.tsx
import { ChartCard, BarChart } from "ztd-charts";

const data = [
  {"quarter":"Q1","team":"Domestic","revenue":42},
  {"quarter":"Q1","team":"Overseas","revenue":18},
  {"quarter":"Q2","team":"Domestic","revenue":48},
  {"quarter":"Q2","team":"Overseas","revenue":24},
  {"quarter":"Q3","team":"Domestic","revenue":51},
  {"quarter":"Q3","team":"Overseas","revenue":33},
  // … 2 more rows
];

export function Example() {
  return (
    <ChartCard number="16" title="Bar chart" subtitle="Revenue by quarter (100M KRW)" takeaway="Overseas grows its share every quarter" level="basic" replay>
      <BarChart
        data={data}
        x="quarter"
        y="revenue"
        series="team"
        layout="stacked"
        highlight="Overseas"
      />
    </ChartCard>
  );
}

Props

<BarChart> takes these props. Rows marked Common work the same on every chart.

32 props

Prop
dataRequiredAn array of objects. Pass CSV, REST or database rows as they areobject[]
xRequiredCategory fieldstring | (d, i) => string
yRequiredValue field. An array for wide tablesstring | (d, i) => number | string[]
seriesSeries fieldstring | (d, i) => string
lineLines over vertical bars on the same axis, such as a target or last year. An array for several. Bars stay gray unless highlight is set, and with series the line averages rows of the same xstring | (d, i) => number | string[]
layoutHow series are arranged"grouped" | "stacked" | "percent"Default "grouped"
orientationDirection"vertical" | "horizontal"Default "vertical"
sortSort by value (single series)booleanDefault false
aggregateHow rows with the same x (and series) combine: "sum" adds them, "mean" averages, "last" keeps the last row, "count" counts rows"sum" | "mean" | "last" | "count"Default "sum"
annotationsNotes drawn on vertical bars: target band, period, reference line, event, forecast (later bars turn pale with a dashed outline), trend line. [{ type, x, y, from, label }]annotations
hiddenSeries to hide. Colors stay as if every series were shown. With card.legend "toggle", viewers can show them againstring[]
heightCommonHeight in px. Without it, each chart picks a default that fits its widthnumber
widthCommonFixed width in px. Without it, the chart fits its parentnumber
highlightCommonItem to highlight. An index, a name, an array, or "max" | "min" | "first" | "last" | "none"number | string | (number|string)[] | "max" …
formatCommonValue format. "number" | "integer" | "percent" (values are already percents: 42 → "42%") | "ratio" (0.42 → "42%") | "compact" | "currency" (KRW for Korean locales, otherwise USD; for another currency pass Intl options with currency) | "decimal" or Intl.NumberFormat options"number" | "percent" | "compact" | …
unitCommonUnit appended to values. For example "%" or "ms"string
localeCommonLocale for numbers, dates and the text a chart writes itself (tooltips, screen reader sentences). "ko" or "ko-*" switches to Korean. Falls back to the ThemeProvider localestringDefault "en-US"
animateCommonEntry and update animationbooleanDefault true
durationCommonAnimation length (ms)number
easingCommonMotion curve"spring" | "easeOut" | "easeInOut" | "linear"Default "spring"
staggerCommonDelay between items as they enter (ms)number
reducedMotionCommon"auto" follows the OS setting. true always turns motion offanyDefault "auto"
animateOnViewCommonPlay when the chart scrolls into viewbooleanDefault true
showLabelsCommonLabels drawn on the chart (values and names)booleanDefault true
tooltipCommonShow tooltips. { template: "{label} · {value} · owner {owner}" } writes them: {label}, {value}, {series} or any other column of the row. \n starts a new line, and a line with an empty value is left outtooltipDefault true
syncIdCommonCharts with the same syncId show the hovered x together (line, area, bar, candlestick). <ChartGrid sync> sets one for every chart inside itstring
ariaLabelCommonName for screen readersstring
descriptionCommonDescription for screen readers. Built from the data when omittedstring
onHoverCommonRuns when hover or keyboard focus moves to another item(e: ChartEvent | null) => void
onClickCommonRuns on click, Enter or Space(e: ChartEvent) => void
replayKeyCommonReplays the entry animation when it changesstring | number
themeCommonChanges theme tokens for this chart onlyPartial<ChartTheme>