# React Native Funnel Chart (Pro)

> A React Native funnel chart for iOS, Android and the web: conversion stages as centred bars with connectors, each stage's count and its share of the first or the previous step, animated data, tooltips by touch, pointer or keyboard, and a screen-reader summary of each drop-off.

# Funnel chart Pro

The stages people drop out of, top to bottom: visits, sign-ups, trials, paid. Each bar is as wide as its count, joined to the next by a faint connector, with the count and its share of the first stage (or the step before, with `percentOf="previous"`) beside it. Screen readers hear each step's conversion and the overall one.

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

## Live data

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

const roll = () => {
  let people = 8000 + Math.round(Math.random() * 8000);
  return ['Visited', 'Signed up', 'Started trial', 'Subscribed'].map((stage, i) => {
    if (i) people = Math.round(people * (0.25 + Math.random() * 0.45));
    return { stage, people };
  });
};

export default function Example() {
  const [data, setData] = useState(roll);
  const [step, setStep] = useState(false);
  return (
    <View style={{ width: '100%', maxWidth: 380, gap: 8 }}>
      <View style={{ flexDirection: 'row', gap: 8, justifyContent: 'flex-end' }}>
        <Button size="sm" variant="outline" onPress={() => setStep((s) => !s)}>{step ? 'Of first' : 'Of previous'}</Button>
        <Button size="sm" variant="outline" onPress={() => setData(roll())}>Shuffle</Button>
      </View>
      <FunnelChart data={data} nameKey="stage" valueKey="people" percentOf={step ? 'previous' : 'first'} accessibilityLabel="Sign-up funnel, this week" />
    </View>
  );
}
```

## Example: a checkout funnel

A shop's checkout, step by step: switch between phones and computers to see where each loses people. Shown against the previous step, the biggest drop stands out.

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

const STEPS = ['Viewed a product', 'Added to cart', 'Started checkout', 'Entered payment', 'Paid'];
const DEVICES = {
  phone: [24800, 5210, 2890, 1460, 1190],
  computer: [11200, 3020, 2210, 1810, 1640],
};

export default function Example() {
  const [device, setDevice] = useState<keyof typeof DEVICES>('phone');
  const data = STEPS.map((step, i) => ({ step, people: DEVICES[device][i] }));
  const rate = ((data[4].people / data[0].people) * 100).toFixed(1);
  return (
    <View style={{ width: '100%', maxWidth: 560, gap: 12 }}>
      <SegmentedControl items={[{ label: 'Phones', value: 'phone' }, { label: 'Computers', value: 'computer' }]} value={device} onValueChange={setDevice} style={{ alignSelf: 'flex-start' }} />
      <FunnelChart data={data} nameKey="step" valueKey="people" percentOf="previous" accessibilityLabel={`Checkout funnel on ${device}s`} />
      <Text size="sm" color="textSecondary">{rate}% of visitors paid</Text>
    </View>
  );
}
```

## Props

The [shared chart props](./charts#shared-props) except the legend, and:

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `nameKey` | `string` | — | The row field naming each stage, top to bottom. |
| `valueKey` | `string` | — | How many reached it. |
| `series` | `{ key, label?, color? }[]` | — | Labels and colors for stages. |
| `percentOf` | `'first' \| 'previous'` | `'first'` | Each stage's share of the first stage or the one before. |
| `colorful` | `boolean` | `false` | A palette color per stage instead of one color. |
| `height` | `number` | 52 per stage | |
