# React Native Line & Area Chart (Pro)

> React Native line and area charts for iOS, Android and the web: live data that glides to new values, stacked and 100% areas, gradient fills, step and monotone curves, dashed forecasts, reference lines and bands, currency and percent axes, legend toggles, scrubbing with haptic-ready callbacks, loading and empty states, RTL and screen-reader trend summaries.

# Line & Area chart Pro

Trends over time, one line per series. `AreaChart` fills under each line with a fading gradient, or stacks the series (`stacked`, or `stacked="percent"` for shares of 100%). Drag a finger across it on a phone, hover on the web, or focus it and use the arrow keys: the crosshair snaps to each point and `onPointSelect` hears every move, the place for a haptic tick or a header readout. When `data` changes, the lines glide to their new values.

```tsx
import { AreaChart, LineChart } from '@patine-ui/pro';
```

## Live data

A feed that ticks every second. Scrub it to read a point into the header; the line keeps moving under your finger.

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

const next = (last) => Math.max(20, Math.round(last + (Math.random() - 0.45) * 18));
const start = () => {
  let v = 120;
  return Array.from({ length: 24 }, (_, i) => ({ t: i, cpu: (v = next(v)), p95: Math.round(v * 1.3) }));
};

export default function Example() {
  const [data, setData] = useState(start);
  const [live, setLive] = useState(true);
  const [picked, setPicked] = useState(null);
  useEffect(() => {
    if (!live) return;
    const id = setInterval(
      () => setData((rows) => {
        const last = rows[rows.length - 1];
        const cpu = next(last.cpu);
        return [...rows.slice(1), { t: last.t + 1, cpu, p95: Math.round(cpu * 1.3) }];
      }),
      1000
    );
    return () => clearInterval(id);
  }, [live]);
  const shown = picked ? data[picked.index] : data[data.length - 1];
  return (
    <View style={{ width: 380, gap: 8 }}>
      <View style={{ flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center' }}>
        <View>
          <Text style={{ opacity: 0.7 }}>{picked ? `At ${picked.label}s` : 'Latency now'}</Text>
          <Text style={{ fontSize: 28, fontWeight: '700' }}>{shown ? `${shown.cpu} ms` : '–'}</Text>
        </View>
        <View style={{ flexDirection: 'row', gap: 8 }}>
          <Button size="sm" variant="outline" onPress={() => setLive((v) => !v)}>{live ? 'Pause' : 'Resume'}</Button>
          <Button size="sm" variant="outline" onPress={() => setData(start())}>Reset</Button>
        </View>
      </View>
      <AreaChart
        data={data}
        xKey="t"
        series={[{ key: 'cpu', label: 'Median' }, { key: 'p95', label: 'p95', dashed: true }]}
        valueFormatter={(v) => `${v} ms`}
        referenceBands={[{ from: 0, to: 100, label: 'SLO' }]}
        onPointSelect={setPicked}
        showDots={false}
        height={220}
        accessibilityLabel="API latency, last 24 seconds"
      />
    </View>
  );
}
```

## Example: traffic after a launch

A product's analytics: this month's visitors against last month's, dashed, with a line at the launch day. Press a day to read both numbers.

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

const data = Array.from({ length: 30 }, (_, i) => {
  const base = 3200 + Math.sin(i / 2.2) * 400;
  return { day: i + 1, now: Math.round(base + (i >= 14 ? 2600 * Math.exp(-(i - 14) / 6) + 900 : 0)), before: Math.round(base * 0.92) };
});

export default function Example() {
  const [picked, setPicked] = useState<{ index: number } | null>(null);
  const row = data[picked?.index ?? data.length - 1];
  return (
    <View style={{ width: '100%', gap: 8 }}>
      <HStack gap="xl">
        <VStack>
          <Text size="sm" color="textSecondary">Visitors, Nov {row.day}</Text>
          <Text size="2xl" weight="semibold">{row.now.toLocaleString()}</Text>
        </VStack>
        <VStack>
          <Text size="sm" color="textSecondary">Same day last month</Text>
          <Text size="2xl" color="textSecondary">{row.before.toLocaleString()}</Text>
        </VStack>
      </HStack>
      <LineChart
        data={data}
        xKey="day"
        series={[{ key: 'now', label: 'November' }, { key: 'before', label: 'October', dashed: true }]}
        referenceLines={[{ value: 6500, label: 'Record day', dashed: true }]}
        valueFormat="compact"
        showDots={false}
        onPointSelect={setPicked}
        height={240}
        accessibilityLabel="Daily visitors, November against October"
      />
    </View>
  );
}
```

## Gallery

### Actuals and a forecast

`dashFrom` draws a series solid up to an index and dashed after it: actuals, then the projection. A reference line marks the target, and `valueFormat="currency"` writes `$1.2K` on the axis and `$1,234.00` in the tooltip.

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

const data = [
  { month: 'Jan', revenue: 18600, plan: 20000 },
  { month: 'Feb', revenue: 30500, plan: 22000 },
  { month: 'Mar', revenue: 23700, plan: 24000 },
  { month: 'Apr', revenue: 27300, plan: 26000 },
  { month: 'May', revenue: 29900, plan: 28000 },
  { month: 'Jun', revenue: 33400, plan: 30000 },
  { month: 'Jul', revenue: 36100, plan: 32000 },
  { month: 'Aug', revenue: 39800, plan: 34000 },
];

export default function Example() {
  return (
    <LineChart
      data={data}
      xKey="month"
      series={[
        { key: 'revenue', label: 'Revenue', dashFrom: 5 },
        { key: 'plan', label: 'Plan', dashed: true },
      ]}
      valueFormat="currency"
      referenceLines={[{ value: 35000, label: 'Q3 goal' }]}
      accessibilityLabel="Revenue against plan, with a forecast from June"
      style={{ width: 380 }}
    />
  );
}
```

### Stacked and 100% areas

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

const data = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'].map((day, i) => ({
  day,
  organic: 120 + i * 18 + (i % 2) * 30,
  paid: 80 + ((i * 37) % 60),
  referral: 40 + ((i * 13) % 35),
}));

export default function Example() {
  const [mode, setMode] = useState('stacked');
  return (
    <View style={{ width: 380, gap: 12 }}>
      <SegmentedControl
        items={[{ label: 'Stacked', value: 'stacked' }, { label: '100%', value: 'percent' }, { label: 'Overlap', value: 'none' }]}
        value={mode}
        onValueChange={setMode}
      />
      <AreaChart
        data={data}
        xKey="day"
        series={[{ key: 'organic', label: 'Organic' }, { key: 'paid', label: 'Paid' }, { key: 'referral', label: 'Referral' }]}
        stacked={mode === 'none' ? false : mode}
        legendPosition="top"
      />
    </View>
  );
}
```

### Steps, dates and gaps

A step curve for values that hold until they change (prices, plans, stock). `Date`s on the x axis get a time scale, and a `null` breaks the line instead of inventing a value; `connectNulls` draws across it.

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

const data = [
  { day: new Date(2026, 9, 1), price: 12 },
  { day: new Date(2026, 9, 6), price: 12 },
  { day: new Date(2026, 9, 11), price: 15 },
  { day: new Date(2026, 9, 16), price: null },
  { day: new Date(2026, 9, 21), price: 14 },
  { day: new Date(2026, 9, 26), price: 18 },
  { day: new Date(2026, 9, 31), price: 18 },
];

export default function Example() {
  return (
    <LineChart
      data={data}
      xKey="day"
      series={[{ key: 'price', label: 'Price' }]}
      curve="stepAfter"
      valueFormat="currency"
      grid="both"
      height={200}
      style={{ width: 380 }}
    />
  );
}
```

### Loading, error and empty

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

const series = [{ key: 'v', label: 'Visits' }];

export default function Example() {
  return (
    <View style={{ width: 380, gap: 12 }}>
      <LineChart data={[]} xKey="d" series={series} loading height={120} />
      <LineChart data={[]} xKey="d" series={series} error="Couldn't load visits. Pull to retry." height={80} />
      <LineChart data={[]} xKey="d" series={series} emptyLabel="No visits this week yet" height={80} />
    </View>
  );
}
```

## Accessibility

- A chart is one image to a screen reader, named by `accessibilityLabel` and a summary of each visible series: how many values over what span, the lowest and highest and where, and the trend.
- On the web it takes focus: arrows move the cursor, Home and End jump to the ends, Escape hides it. The tooltip is a polite live region.
- Every series has its own marker shape, so color is never the only cue; legend items are checkboxes that turn a series off and on (the last one stays on), with 44pt touch targets.
- Growing in and gliding to new data are skipped when the OS asks to reduce motion.

## Props

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

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `curve` | `'monotone' \| 'linear' \| 'step' \| 'stepAfter' \| 'stepBefore'` | `'monotone'` | Monotone is smooth and never overshoots the data. |
| `showDots` | `boolean \| 'auto'` | `'auto'` | `'auto'`: every point up to 24, then only the last. |
| `connectNulls` | `boolean` | `false` | Draw across missing values. |
| `strokeWidth` | `number` | the design's | |
| `stacked` | `boolean \| 'percent'` | `false` | `AreaChart` only: stack the series, or scale each column to 100%. |
| `gradient` | `boolean` | `true` | `AreaChart` only: a fill that fades toward the baseline. |

Series take `dashed` (the whole line) and `dashFrom` (dashed from that data index on, for a forecast).
