Skip to main content

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.

Loading…
<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​

Props
stacked
barWidth
grid
legendPosition
design
<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.

Loading…
<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>

Goals and value labels​

A bar per rep against their quota, horizontal so names fit, with each value at its bar's end.

Loading…
<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.

Loading…
<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.

Loading…
<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:

PropTypeDefaultDescription
stackedboolean | 'percent'falseOne bar per category, series stacked; 'percent' scales each bar to 100%.
horizontalbooleanfalseBars run left to right.
goalKeystring—A row field with each category's target, drawn as a mark across its bar.
showValuesbooleanfalseEach bar's value at its end (side-by-side bars).
barWidthnumber0.72The share of its band a bar group takes, 0–1.
radiusnumberthe design'sCorner radius of the value end.