Command palette

@yasinsensoy/native

React Native · Components

Chart

Chart: bar, line, area, pie, donut and scatter.

18 exports

Live example

The preview runs in the browser with the web component; the native component takes the same props and looks the same on iOS and Android.

Preview

Use the arrow keys to move between values.
Monthly revenue
ayRevenueExpenses
Jan$42,000$36,000
Feb$50,094$36,865
Mar$56,509$36,442
Apr$60,131$35,224
May$60,785$33,903
Jun$59,292$33,193
Jul$57,196$33,660
Aug$56,245$35,581
Sep$57,800$38,878
Oct$62,380$43,135
Nov$69,488$47,702
Dec$77,777$51,852

Code

import { Chart } from "@yasinsensoy/native";

<Chart
  data={aylik}
  x="ay"
  series={[{ key: "income", label: "Revenue" }, { key: "expense", label: "Expenses" }]}
  format="currency" zoom
  label="Monthly revenue"
/>

Events

  1. Events appear here when you interact with the preview.

Zoom: 100,000 points, range navigator and the selected range

All data
Use the arrow keys to move between values.

Zooming on categories: 36 months, the last 12 at first

Use the arrow keys to move between values.
Monthly revenue and expenses
ayRevenueExpenses
Jan 2442K36K
Feb 2448.4K36.2K
Mar 2453.1K35K
Apr 2455K33.1K
May 2454K31.1K
Jun 2450.8K29.7K
Jul 2447K29.5K
Aug 2444.3K30.7K
Sep 2444.2K33.3K
Oct 2447.1K36.8K
Nov 2452.5K40.7K
Dec 2459.1K44.2K
Jan 2565.1K46.6K
Feb 2569K47.6K
Mar 2570K47.1K
Apr 2568.1K45.6K
May 2564.5K43.5K
Jun 2560.9K41.7K
Jul 2558.9K40.7K
Aug 2559.7K41.1K
Sep 2563.5K43K
Oct 2569.5K46K
Nov 2576.1K49.8K
Dec 2581.6K53.6K
Jan 2684.6K56.7K
Feb 2684.6K58.5K
Mar 2682K58.8K
Apr 2678.2K57.9K
May 2675K56K
Jun 2673.8K54K
Jul 2675.6K52.4K
Aug 2680.2K52K
Sep 2686.6K53.1K
Oct 2693K55.5K
Nov 2697.8K58.9K
Dec 2699.9K62.8K

Inside a card: title, summary and bars + a line (target) together

Revenue and target

2026, monthly
18% up
Use the arrow keys to move between values.
Revenue and target
ayRevenueTarget
Jan$42,000$50,000
Feb$50,094$52,500
Mar$56,509$55,000
Apr$60,131$57,500
May$60,785$60,000
Jun$59,292$62,500
Jul$57,196$65,000
Aug$56,245$67,500
Sep$57,800$70,000
Oct$62,380$72,500
Nov$69,488$75,000
Dec$77,777$77,500

Sparkline: stat boxes (server component)

Visitors
48,2 B
Conversion
%3,4
Orders
1.284

Horizontal bars, long names and value labels

Use the arrow keys to move between values.
Sales by city
citySales
İstanbul1,840
Ankara920
İzmir760
Bursa410
Antalya380

Negative values: profit / loss

Use the arrow keys to move between values.
Net profit
ayNet
Jan0
Feb10.1K
Mar10.9K
Apr1.7K
May-9.1K
Jun-11.5K
Jul-3.4K
Aug7.9K

Import

import { Chart, Sparkline } from "@yasinsensoy/native";

Chart

component

Chart: bar, line, area, pie, donut and scatter. Calculations are the same as web's Chart (@yasinsensoy/core/chart): axis range, nice ticks, abbreviated numbers, date axis, downsampling. Drawing uses our own native view; no external library, identical on iOS and Android.

  • Touch: dragging a finger sideways makes the tooltip follow the values; vertical dragging scrolls the page. Tapping an empty area closes the tooltip.
  • Legend: appears with multiple series; tapping hides a series. Colors are bound to series, so hiding one does not change the others.
  • Colors come from the theme's chart palette and change automatically in dark theme.
Chart({ data, type, x, series, label, height: heightProp, stacked, horizontal, curve, dots, legend, tooltip, renderTooltip, grid, xAxis, yAxis, format, xFormat, yMin, yMax, labels, references, colors, barSize, center, maxSlices, loading, empty, animate, onPointClick, locale: localeProp, currency: currencyProp, zoom, range, defaultRange, onRangeChange, style, }: ChartProps<T>): JSX.Element

Examples

<Chart data={sales} x="month" series={["revenue", "expense"]} format="currency" />
<Chart type="line" data={daily} x="date" series={[{ key: "visits", label: "Visits" }]} />
<Chart type="donut" data={browsers} x="name" series="share" format="percent" />

Sparkline

component

Small chart showing a trend next to text or a number (no axes). Its width fits the container; drawing uses the same paths as web's Sparkline.

Sparkline({ data, type, color, height: heightProp, endDot, label, style, }: SparklineProps): JSX.Element

Examples

<Sparkline data={[12, 14, 13, 18, 21, 19, 24]} type="area" color="success" style={{ width: 96 }} />

Shape of the line between points.

type ChartCurve = "smooth" | "linear" | "step"

Chart type. See ChartProps.type.

type ChartType = "bar" | "line" | "area" | "pie" | "donut" | "scatter"

ChartSeries

interface

Detailed definition of a Chart series (same as web).

NameTypeDefaultDescription
keyKey<T> | (string & {})Field the value is read from. It is the series' ID; must be unique.
label?stringkeyName in the legend and tooltip.
color?ChartColorits position in the paletteColor.
type?ChartSeriesTypethe chart's `typeDrawing type of this series (bars + line together).
value?(row: T) => number | null | undefinedReads the value from a function.
format?ChartFormatthe chart's `formatValue format of this series.
curve?ChartCurvethe chart's `curveLine curve.
dashed?booleanDashed line.
dots?booleantrue` with few pointsShow points on the line.
hidden?booleanThe series starts hidden; can be shown from the legend.

Format of chart values (y axis, tooltip, labels).

  • "number": Locale-grouped number (12,480). On the axis, values above 10,000 are abbreviated (12.5K).
  • "compact": Abbreviated everywhere (1.2M).
  • "percent": A ratio as a percentage (0.25 → 25%).
  • "currency": Money ($1,250.00); the unit comes from the UIProvider currency setting or the chart's currency prop.
  • Intl.NumberFormatOptions: Full control (e.g. { style: "unit", unit: "kilogram" }).
  • Function: Your own format (e.g. (v) => ${v} pcs``).
type ChartFormat = "number" | "compact" | "percent" | "currency" | Intl.NumberFormatOptions | ((value: number) => string)

How a series is drawn. In bar and line charts it may differ per series.

type ChartSeriesType = "bar" | "line" | "area"

Color: a tone ("success"), a palette index ("chart-3") or any CSS color ("#7c3aed", "var(--brand)"). When omitted, series take --ui-chart-1 … --ui-chart-8 in order.

type ChartColor = Tone | `chart-${1 | 2 | 3 | 4 | 5 | 6 | 7 | 8}` | (string & {})

Format of chart x values (axis and tooltip title).

  • "date": Day (Oct 29, 2026), "datetime": day and time, "time": time, "month": month and year, "year": year.
  • Intl.DateTimeFormatOptions: Full control.
  • Function: Your own format; receives the raw x value.

When omitted, dates are formatted automatically by time range and other values are written as is.

type ChartXFormat = "date" | "datetime" | "time" | "month" | "year" | Intl.DateTimeFormatOptions | ((value: unknown) => string)

A horizontal or vertical reference line (target, average, limit).

NameTypeDefaultDescription
valuenumberValue of the line (on the y axis; on the value axis for horizontal bars).
label?stringShort text next to the line (e.g. "Target").
tone?Tone"neutral"Color.

ChartPoint

interface

A data point; passed in the press event.

NameTypeDescription
rowTThe row itself.
indexnumberIndex of the row in data.
seriesstringkey of the series.
valuenumber | nullValue (null = empty).

A row in the tooltip.

NameTypeDescription
keystringkey of the series.
labelstringName of the series.
colorstringColor of the series.
valuenumber | nullValue (null = empty).
formattedstringFormatted value.
share?numberShare in a percent stack or pie (0–1).

Info passed to ChartProps.renderTooltip.

NameTypeDescription
titlestringTitle: the formatted x value; the slice name in a pie.
rowT | undefinedThe row (undefined for the "Other" slice).
indexnumberIndex of the row (-1 for the "Other" slice).
itemsChartTooltipItem[]Values of the series.

ChartProps

interface

Props of Chart. Names match web's Chart.

NameTypeDefaultDescription
datareadonly T[]Rows. For large data keep the array stable with useMemo.
type?ChartType"bar"Chart type: bar, line, area, pie, donut, scatter.
xKey<T> | ((row: T) => unknown)Field of the x value (category, date or number). The slice name in a pie.
seriesKey<T> | readonly (Key<T> | ChartSeries<T>)[]Values to draw: a field, fields or detailed definitions.
label?stringScreen reader name (e.g. "Monthly revenue").
height?number260`, `240` for piesHeight of the plot area. Width fits the container.
stacked?boolean | "percent"Stacks bar and area series; "percent" is a 100% stack.
horizontal?booleanHorizontal bars.
curve?ChartCurve"smooth"Line curve.
dots?booleantrue` with few pointsPoints on lines.
legend?boolean | "top" | "bottom""bottom"` with multiple series and for piesLegend; tapping hides/shows a series.
tooltip?booleantrueTooltip showing values on tap and while dragging a finger.
renderTooltip?(info: ChartTooltipInfo<T>) => ReactNodeRender the tooltip content yourself.
grid?booleantrueGrid lines.
xAxis?booleantruex-axis labels.
yAxis?booleantrueValue axis labels.
format?ChartFormat"number"Value format.
xFormat?ChartXFormatFormat of x values.
yMin?numberLower bound of the value axis.
yMax?numberUpper bound of the value axis.
labels?booleanValue labels (only those that fit).
references?readonly ChartReference[]Reference lines (target, average).
colors?readonly ChartColor[]Colors to use in order.
barSize?number32Maximum bar thickness.
center?ReactNode | falseCenter of the donut; defaults to the total, or the tapped slice. false leaves it empty.
maxSlices?number8Maximum slices in a pie; the rest are grouped into "Other".
loading?booleanData loading: faded if there is data, a skeleton otherwise.
empty?ReactNodethe {@link UIProvider} `chartEmpty` textContent shown when there is no data.
animate?booleantrueFade in on mount. Off while "reduce motion" is on.
onPointClick?(point: ChartPoint<T>) => voidWhen a value is tapped.
zoom?boolean | ChartZoomOptionsZoom (except pies): pinch with two fingers, pan with one finger while zoomed, double-tap to reset; +/−/reset buttons in the corner.
range?ChartRange | nullVisible range (controlled). null is all data. Pass it together with onRangeChange. See ChartRange.
defaultRange?ChartRangeInitial visible range (uncontrolled).
onRangeChange?(range: ChartRange | null) => voidWhen the visible range changes; null when back to all. May be called on every move while zooming; defer expensive work.
locale?string{@link UIProvider} `localeLocale.
currency?string{@link UIProvider} `currencyCurrency.
style?StyleProp<ViewStyle>Container style.

Value of the ChartRange ends: an x value (category name, number or date).

type ChartRangeValue = string | number | Date

Visible range: two end x values (same as web).

type ChartRange = readonly [ChartRangeValue, ChartRangeValue]

Settings of ChartProps.zoom.

NameTypeDefaultDescription
toolbar?booleantrueZoom out / zoom in / reset buttons at the top right.

Props of Sparkline.

NameTypeDefaultDescription
datareadonly (number | null | undefined)[]Values; null is a gap.
type?"line" | "area" | "bar""line"Drawing type.
color?ChartColor"chart-1"Color: a semantic color, "chart-3" or any color.
height?number32Height (px). Width fits the container.
endDot?booleantrueHighlight the last value with a dot (line and area).
label?stringScreen reader text (e.g. "Last 12 months: rising"). Hidden if not given.
style?StyleProp<ViewStyle>Container style (for width).