ComponentsBarChart

Bar Chart

Bar charts compare values across categories, in the Shoreline design language with zero styling effort.

🧪

Experimental. BarChart is not stable yet: it ships in @vtex/shoreline-charts at 0.x, so its API and visuals may change between minor versions.

BarChart lives in the separate @vtex/shoreline-charts package. Install it and import its stylesheet once in your app:

pnpm add @vtex/shoreline-charts
import { BarChart } from '@vtex/shoreline-charts'
import '@vtex/shoreline-charts/css'

Examples

Variants

direction sets the bar orientation: vertical (the default) or horizontal.

Grouping

grouping controls how multiple series combine: grouped (the default) places them side by side, stacked piles them into a single bar per category.

Series aggregation

Only maxSeries series render (default 3); the rest fold into a single Others aggregate that takes the last slot’s color. Raise maxSeries to give more series their own name and color. It is capped at 6 — the palette length — and series past the cap still aggregate, so raising maxSeries never drops data.

Tooltip with deltas

Each series can carry a deltas array — one entry per category — shown in the hover tooltip beside the value. direction (up / down / flat) and tone (success / critical / neutral) are independent, because a decrease is not inherently bad: falling complaints is direction: 'down' with tone: 'success'. The comparison data need not be plotted — it only feeds the tooltip.

Loading state

Pass loading to show a skeleton placeholder instead of the chart while data is being fetched.

Empty state

When no series has any non-null value, the chart renders its empty state. Override the message through the messages prop, or let it localize from the surrounding LocaleProvider.

Negative values

Negative values render below the zero line. Corner radius is resolved per bar from the value’s sign, so bars below zero round at their far end rather than at the zero line — including the outermost segment of a stacked bar with mixed signs.

Localization

Internal messages — the empty state and the Others aggregate — localize from the surrounding LocaleProvider. Data supplied through props is not translated: series names and categories are the consumer’s to localize.

Required props

series

Chart series. Multiple series render per the grouping prop. At most maxSeries of them render: past that, the tail is summed per category into a single aggregate series named after the others message.

type
BarChartSeries[]
default
null

categories

Labels of the category axis, in render order. Every series provides one value per category.

type
string[]
default
null

label

Accessible name announced for the chart.

type
string
default
null

Optional props

description

Accessible long description of what the chart shows.

type
string
default
undefined

direction

Orientation of the bars.

type
BarChartDirection
default
vertical

grouping

How multiple series combine: side by side or stacked.

type
BarChartGrouping
default
grouped

loading

Shows a loading placeholder instead of the chart.

type
boolean
default
false

messages

Overrides the chart's internal messages, which are otherwise localized from the surrounding LocaleProvider.

type
Partial<{ empty: string; others: string; }>
default
undefined

maxSeries

How many series render at most. Raise it to give more series their own name and color instead of aggregating them; the default keeps the chart to the primary and secondary series plus the aggregate.

Capped at 6 — the palette has that many colors and never cycles them. Series past the cap still aggregate, so no data is dropped.

type
number
default
3