Bar chart
Compare categories with signed grouped or stacked bars.
npx @swipeui/cli add bar-chartWhen to use it
- Compare categories with signed grouped or stacked bars.
When not to use it
- Use Metric card when one headline number answers the question without a full plot.
Installation
Installs with a Pro licence
Everything on this page is public except the source. Founder pre-sale opens around 5 January 2027.
Usage
import { BarChart } from '@/components/swipeui/chart/bar-chart';
<BarChart label="Orders" series={[{ id: "orders", label: "Orders" }]} data={[{ id: "mon", label: "Mon", values: { orders: 24 } }, { id: "tue", label: "Tue", values: { orders: 32 } }]} />Examples
weekly, spending, stacked, small, medium, large. App and public preview use the same original scenario data. Range and feature controls stay outside the component.
- small: two half-width cards, each with today's total and thin hourly capsules under dashed six-hour guides.
- medium: a wide card with the latest value on the left and the week on the right, every night muted except the last.
- large: a range picker (day, week, month, year), the total, and a tall chart with gradient bars, its scale on the right and dashed time guides.
The card layouts are demo compositions; the chart inside each is one BarChart:
// Small card chart: hourly capsules labelled every six hours.
<BarChart
label="Cycling today"
data={hours}
series={[{ id: 'value', label: 'Minutes', color: tint }]}
height={112}
cornerRadius="full"
barSize={5}
minBarSize={3}
guides="dashed"
xLabelEvery={6}
xLabelAlign="start"
yAxis={false}
grid={false}
legend={false}
/>
// Medium card chart: the latest night stands out.
<BarChart label="Sleep this week" data={week} series={series} height={64} highlight="latest"
barSize={12} xAxis={false} yAxis={false} grid={false} legend={false} />
// Large chart: scale on the right, gradient bars, dashed guides.
<BarChart label="Ride distance" data={days} series={series} height={300} yAxisSide="end"
guides="dashed" xLabelEvery={6} xLabelAlign="start" gradient minBarSize={2} legend={false} />Settings
| Prop | Default | Behaviour |
|---|---|---|
tooltipPlacement | plot | Place inspection inside the plot or above it. |
tooltipWidth | 184 | Readout width bounded by the visible plot. |
renderTooltip | default card | Custom inspection content; streamgraph supplies a coloured multi-row comparison. |
dismissOnOutsidePress | true | Clear floating inspection when touching outside a chart under ChartInteractionProvider. |
cornerRadius | 5 | Curvature at bar tips; the baseline corners stay square. 'full' draws capsules rounded at both ends. |
barSize | — | The widest a bar may draw, in points. |
highlight | — | 'latest' or a category ID: that bar keeps its colour and the rest draw muted. |
guides | 'none' | 'solid' or 'dashed' vertical lines at the labelled categories. |
xLabelEvery | about seven | Label every n-th category, such as 6 for hours. |
xLabelAlign | 'center' | Centre labels on their bar, or 'start' them just after their guide. |
yAxisSide | 'start' | Put the numbers on the 'end' edge. |
gradient | false | Fade each bar toward its base. |
minBarSize | 0 | Smallest visible length for a non-zero bar, so tiny values still show. |
data | — | Ordered categories; missing values are not fabricated. |
series | — | Measures read from each category's values. |
orientation | 'vertical' | Bar direction. |
mode | 'grouped' | Side-by-side or separate positive/negative stacks. |
valueLabels | false | Label each category total. |
referenceValue | — | Horizontal/vertical comparison line. |
grid | true | Numeric guide lines. |
xAxis | true | Show category axis labels. |
yAxis | true | Show numeric axis labels. |
label | — | Short accessible chart name. |
summary | — | Written description of the pattern, in the caller's words. |
loading | false | Show shimmer placeholders and expose the busy state. |
invalid | false | Explicitly unavailable dataset. |
interactive | true | Enable plot interaction and accessible value stepping. |
tooltip | true | Compact floating value card over the selected observation. |
legend | true | Show a labelled series/category key. |
legendPosition | 'bottom' | Put the key under the plot or 'top' above it. |
haptics | true | Tick when a different observation is selected. |
reveal | true | Reveal geometry on first appearance. |
animateData | true | Morph data changes; resize snaps. |
active | true | Pause ambient effects on hidden routes. |
selectedId | — | Controlled observation ID; null clears selection. |
defaultSelectedId | null | Initial observation when uncontrolled. |
onSelectionChange | — | Called only when semantic selection changes. |
locale | — | Device locale unless overridden. |
formatValue | — | Override value formatting. |
messages | — | Translatable built-in strings. |
motion | — | Inherited SwipeUI motion feel. |
height | 208 | Plot height in points; text flows outside it. |
className | — | Root class escape hatch. |
style | — | Root native layout escape hatch. |
testID | — | Stable root identifier. |
Accessibility
The plot exposes its name, summary and original values. Accessible value stepping and labelled keys supplement touch. Decorative marks do not repeat the readout. Reduced motion removes geometry travel.
Presentation
Bars have rounded tips and square bases. The card centres the graph with bold numeric ticks and all seven weekday initials, without an axis line. Compare adds a second series; exact values appear in floating inspection. The improvement footer has been removed.
Layout and data
Measure from the parent; let labels and keys wrap. Use stable IDs. Missing observations are gaps, not zeros. Parts of a whole and flows require nonnegative finite values. Native runtime, screen-reader, haptic and device-performance checks remain pending.
Outside dismissal
Wrap the app or chart screen in ChartInteractionProvider from @/components/swipeui/lib/chart-core. It observes native touches without taking the responder; controls keep their normal behaviour. dismissOnOutsidePress={false} retains a caller-managed selection. Browser demonstrations use pointer observation and Escape.
Behavior and gestures
- Select a labelled observation by touch or accessible value stepping. The caller can control the selection.
- Data changes animate independently from reveal, selection feedback and optional ambient effects.
- Card-size options, each independent: cornerRadius='full' draws capsule bars, barSize caps the bar thickness, highlight mutes every bar but the latest (or one by ID), guides adds solid or dashed vertical lines at the labelled categories, xLabelEvery and xLabelAlign label every n-th category beside its guide, yAxisSide puts the numbers on the end edge, gradient fades each bar toward its base, and minBarSize keeps tiny non-zero values visible as a stub.
Accessibility
- The chart has a written summary and named values. Decorative SVG geometry is hidden from assistive technologies.
- Value stepping, labelled legends and text readouts supplement colour. Native screen-reader runtime validation remains pending.
Motion
- Uses the
morph,selectandambientmotion roles, so it follows your app's feel. Passmotionto tune this one instance. - Geometry transitions use the shared morph role; reduced motion swaps immediately.
- Ambient effects pause offscreen and in the background.
Performance
- Display geometry is bounded for time series; selection retains original data. Native device performance is not yet verified.
Notes for AI
- Use stable IDs and caller-owned data/state. Provide an accessible label and a useful written summary.
- Use ChartCard for an interactive chart composition; keep MetricCard sparkline content decorative.
Compatibility
| Runs on | Supported |
|---|---|
| Expo SDK 57 | Yes |
| Expo SDK 58 | Yes |
| React Native CLI (with Expo modules) | Yes |
| Expo Go | Yes |
| iOS | Yes |
| Android | Yes |
This table describes API support and static bundle checks. Native runtime, device accessibility and bare Uniwind compatibility remain pending.