Skip to main content

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.

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.

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

Try the props​

Props
curve
showDots
valueFormat
grid
referenceLines
legendPosition
design
<LineChart
data={sales}
xKey="month"
series={[{ key: 'revenue', label: 'Revenue' }, { key: 'cost', label: 'Cost' }]}
/>

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.

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

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.

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

Loading…
<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). Dates on the x axis get a time scale, and a null breaks the line instead of inventing a value; connectNulls draws across it.

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

Loading…
<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>
Props
stacked
curve
grid
legendPosition
design
<AreaChart data={traffic} xKey="month" series={devices} />

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, the cartesian props, and:

PropTypeDefaultDescription
curve'monotone' | 'linear' | 'step' | 'stepAfter' | 'stepBefore''monotone'Monotone is smooth and never overshoots the data.
showDotsboolean | 'auto''auto''auto': every point up to 24, then only the last.
connectNullsbooleanfalseDraw across missing values.
strokeWidthnumberthe design's
stackedboolean | 'percent'falseAreaChart only: stack the series, or scale each column to 100%.
gradientbooleantrueAreaChart 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).