# React Native Bar Chart (Pro)

> A React Native bar chart for iOS, Android and the web: grouped, stacked, 100% stacked and horizontal bars, goal marks, value labels, reference lines, negative values, bars that grow into new data, legend toggles, currency and percent axes, loading and empty states, RTL and screen-reader summaries.

# 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.

```tsx
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.

```tsx live
import { useState } from 'react';
import { View } from 'react-native';
import { Button, SegmentedControl } from 'patine-ui';
import { BarChart } from '@patine-ui/pro';

const months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun'];
const roll = () => months.map((month) => ({
  month,
  desktop: 80 + Math.round(Math.random() * 220),
  mobile: 60 + Math.round(Math.random() * 180),
  tablet: 20 + Math.round(Math.random() * 60),
}));

export default function Example() {
  const [data, setData] = useState(roll);
  const [layout, setLayout] = useState('grouped');
  return (
    <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>
  );
}
```

## 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.

```tsx live wide
import { useState } from 'react';
import { View } from 'react-native';
import { SegmentedControl, Text } from 'patine-ui';
import { BarChart } from '@patine-ui/pro';

const WEEKS = {
  this: [52, 48, 61, 57, 74, 88, 30],
  last: [47, 51, 55, 60, 69, 92, 28],
};
const PLAN = [50, 50, 55, 55, 70, 90, 30];
const DAYS = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'];

export default function Example() {
  const [week, setWeek] = useState<keyof typeof WEEKS>('this');
  const data = DAYS.map((day, i) => ({ day, delivered: WEEKS[week][i], plan: PLAN[i] }));
  const short = data.filter((d) => d.delivered < d.plan).length;
  return (
    <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.

```tsx live
import { BarChart } from '@patine-ui/pro';

const data = [
  { rep: 'Maya Cohen', closed: 42000, quota: 40000 },
  { rep: 'Daniel Levi', closed: 31000, quota: 38000 },
  { rep: 'Ana Pérez', closed: 27500, quota: 25000 },
  { rep: 'Sam Okafor', closed: 18200, quota: 30000 },
];

export default function Example() {
  return (
    <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.

```tsx live
import { BarChart } from '@patine-ui/pro';

const data = [
  { q: 'Q1', net: 12000 },
  { q: 'Q2', net: -4500 },
  { q: 'Q3', net: 8200 },
  { q: 'Q4', net: -1200 },
  { q: 'Q1 ’27', net: 15300 },
];

export default function Example() {
  return (
    <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.

```tsx live
import { BarChart } from '@patine-ui/pro';

const data = Array.from({ length: 14 }, (_, i) => ({ day: `${i + 1}`, steps: 4000 + ((i * 2731) % 7000) }));

export default function Example() {
  return (
    <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](./charts#shared-props), the [cartesian props](./charts#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. |
