Comparison · Basic
Bar chart
Grouped, stacked, 100% and horizontal bars, with optional lines on the same axis.
- 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
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
100% stacked
Revenue by quarter (100M KRW)
- Domestic
- Overseas
Horizontal
Revenue by quarter (100M KRW)
- Domestic
- Overseas
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 |
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> |
Also in Comparison
- Waterfall chartBreaks the change from a start value to an end value into its drivers
- Pareto chartBars sorted largest first with a cumulative share line
- Radar chartCompares several metrics at once
- Slope chartChange in size and rank between two points in time
- Dumbbell chartThe gap between two values per item (before and after, target and actual)
- Lollipop chartA line and a dot instead of a bar. Stays light with many items