Examples
Sparkline Pro
A small chart with no axes, for a trend beside a number in a stat card or a list row: a line, a line over a fading fill (variant="area"), or bars (variant="bar"). It glides to new values, so it can tick with live data. Screen readers hear its range and trend ("up 32%, from 120 to 158").
import { Sparkline } from '@patine-ui/pro';
Live data
Loading…
<VStack gap="md" style={{ width: 340 }}> {['line', 'area', 'bar'].map((variant) => ( <HStack key={variant} gap="lg" align="center"> <VStack style={{ width: 120 }}> <Text size="sm" color="textSecondary">{variant === 'bar' ? 'Orders' : variant === 'area' ? 'Revenue' : 'Visitors'}</Text> <Text size="xl" weight="semibold">{last} <Text size="sm" color={change >= 0 ? 'success' : 'danger'}>{change >= 0 ? '+' : ''}{change}%</Text></Text> </VStack> <Sparkline data={data} variant={variant} accessibilityLabel={`${variant} trend`} style={{ flex: 1 }} /> </HStack> ))} </VStack>
Try the props
variantcurveheightdesign<Sparkline data={trend} />
Example: a watchlist
An investing app's watchlist: each row has the last month's prices as a sparkline beside the price and the month's change. The line takes the change's color, so the list reads at a glance.
Loading…
<ListItem key={s.symbol} title={s.symbol} description={s.name} showChevron={false} trailing={ <HStack gap="md" align="center"> <Sparkline data={s.prices} width={64} height={28} color={up ? '#16A34A' : '#DC2626'} accessibilityLabel={`${s.symbol}, last 30 days`} /> <VStack align="flex-end" style={{ width: 92 }}> <Text weight="medium">€{last.toFixed(2)}</Text> <Text size="sm" color={up ? 'success' : 'danger'}>{up ? '+' : ''}{change.toFixed(1)}% · 1M</Text> </VStack> </HStack> } /> ); })} </List>
Props
| Prop | Type | Default | Description |
|---|---|---|---|
data | (number | null)[] | — | The values in order; null breaks the line. |
variant | 'line' | 'area' | 'bar' | 'line' | |
height | number | 32 | |
width | number | fills the container | |
color | string | the theme's primary | |
area | boolean | false | The same as variant="area". |
curve | 'monotone' | 'linear' | 'step' | 'stepAfter' | 'stepBefore' | 'monotone' | |
showLast | boolean | true | A dot on the last value. |
valueFormatter / valueFormat | For the summary. | ||
accessibilityLabel | string | — | |
animate | boolean | true | Grow in and glide to new values. |