Bar chart Pro
Compares categories. Several series sit side by side, on one another with stacked, or as shares of 100% with stacked="percent"; horizontal runs bars left to right with the categories down the side, which fits long labels on a phone. goalKey marks each bar's target, showValues writes its value at its end, and negative values hang below zero. Bars grow in on mount and to new heights when the data changes.
import { BarChart } from '@patine-ui/pro';
Live data
Shuffle the numbers, switch the layout, and press a legend item to take a series out: the bars move rather than jump.
<View style={{ width: 380, gap: 12 }}> <View style={{ flexDirection: 'row', gap: 8, alignItems: 'center' }}> <View style={{ flex: 1 }}> <SegmentedControl items={[{ label: 'Grouped', value: 'grouped' }, { label: 'Stacked', value: 'stacked' }, { label: '100%', value: 'percent' }]} value={layout} onValueChange={setLayout} /> </View> <Button size="sm" variant="outline" onPress={() => setData(roll())}>Shuffle</Button> </View> <BarChart data={data} xKey="month" series={[{ key: 'desktop', label: 'Desktop' }, { key: 'mobile', label: 'Mobile' }, { key: 'tablet', label: 'Tablet' }]} stacked={{ grouped: false, stacked: true, percent: 'percent' }[layout]} accessibilityLabel="Visitors by device" /> </View>
Try the props
stackedbarWidthgridlegendPositiondesign<BarChart data={traffic} xKey="month" series={devices} />
Example: deliveries against the plan
A bakery's delivery round: each day's bar is the orders delivered, the mark across it is the plan, and the values sit at the bar ends so the driver doesn't have to read the axis.
<View style={{ width: '100%', gap: 12 }}> <SegmentedControl items={[{ label: 'This week', value: 'this' }, { label: 'Last week', value: 'last' }]} value={week} onValueChange={setWeek} style={{ alignSelf: 'flex-start' }} /> <BarChart data={data} xKey="day" series={[{ key: 'delivered', label: 'Delivered' }]} goalKey="plan" showValues height={240} accessibilityLabel="Orders delivered each day against the plan" /> <Text size="sm" color="textSecondary">{short ? `${short} days under plan` : 'Every day on plan'}</Text> </View>
Gallery
Goals and value labels
A bar per rep against their quota, horizontal so names fit, with each value at its bar's end.
<BarChart horizontal showValues data={data} xKey="rep" series={[{ key: 'closed', label: 'Closed' }]} goalKey="quota" valueFormat="compact" height={220} accessibilityLabel="Closed deals against quota" style={{ width: 380 }} />
Profit and loss
Negative values hang below zero, and a reference line marks the break-even average.
<BarChart data={data} xKey="q" series={[{ key: 'net', label: 'Net income' }]} valueFormat="currency" referenceLines={[{ value: 5960, label: 'Average' }]} showValues height={220} style={{ width: 380 }} />
Thin bars, no axes
For a card: barWidth thins the bars, and the axes and grid go away.
<BarChart data={data} xKey="day" series={[{ key: 'steps', label: 'Steps' }]} barWidth={0.5} showYAxis={false} grid="none" referenceLines={[{ value: 8000, label: 'Goal' }]} height={140} style={{ width: 380 }} />
Props
The shared chart props, the cartesian props, and:
| Prop | Type | Default | Description |
|---|---|---|---|
stacked | boolean | 'percent' | false | One bar per category, series stacked; 'percent' scales each bar to 100%. |
horizontal | boolean | false | Bars run left to right. |
goalKey | string | — | A row field with each category's target, drawn as a mark across its bar. |
showValues | boolean | false | Each bar's value at its end (side-by-side bars). |
barWidth | number | 0.72 | The share of its band a bar group takes, 0–1. |
radius | number | the design's | Corner radius of the value end. |