How to use
Chart covers six chart types (line, area, bar, column, pie, donut) behind one component and a row-based data API — hand it an array of plain objects plus which fields are the category and the series, and it figures out the rest. Every data point is keyboard-reachable and announces its value, not just hover-only like most charting libraries.
import { Chart } from "oks-ui";The common path: pass data as a plain array of objects, x as the field holding the category (a date, a label), and series for the field(s) to plot. No need to pre-shape data into a categories/series structure — Chart derives it from your rows.
<Chart
type="line"
title="Monthly signups"
data={[
{ month: "Jan", signups: 42 },
{ month: "Feb", signups: 58 },
{ month: "Mar", signups: 51 },
{ month: "Apr", signups: 67 },
]}
x="month"
series="signups"
/>series accepts an array for a multi-line/multi-bar chart — pass an array of accessors (or ChartSeriesDef objects with their own label/color) and Chart plots each one, auto-enabling the legend once there's more than one.
<Chart
type="bar"
data={salesData}
x="quarter"
series={[
{ key: "revenue", label: "Revenue" },
{ key: "cost", label: "Cost" },
]}
/>A series entry can mark itself isProjection to render as a distinct dashed segment — for a forecasted continuation of real data (actuals through today, a projected trend afterward) without needing two separate charts stitched together. Bar and column charts split the same way, rendering projected bars with their own visual treatment on the same axis scale as the real values.
<Chart
type="line"
data={[...actuals, ...forecast]}
x="month"
series={[
{ key: "revenue", label: "Actual" },
{ key: "projectedRevenue", label: "Forecast", isProjection: true },
]}
/>axis/axisX/axisY control tick visibility and formatting independently per axis; legend and tooltip each accept either a boolean to toggle them outright or an options object for finer control (position, formatting). dataFormat applies a shared prefix/suffix/decimal-place format across labels and tooltips at once, for currency or percentage values.
<Chart
type="column"
data={data}
x="month"
series="revenue"
dataFormat={{ prefix: "$", decimals: 0 }}
legend={{ position: "bottom" }}
/>Three opt-in interaction features, each disabled by default: zoom enables axis zoom/pan (mode: "x" for horizontal-only, "xy" for both, plus wheel/pan toggles); export adds an action that downloads the chart as SVG or PNG; fullscreen adds a toggle that expands the chart to fill the viewport. All three default to false/off, since not every chart context wants the extra chrome.
<Chart
type="line"
data={data}
x="date"
series="value"
zoom={{ mode: "x" }}
export={{ formats: ["png", "svg"] }}
fullscreen={{ enabled: true }}
/>isLoading, error, and empty each swap in a dedicated state in place of the plotted chart — pass them straight from whatever data-fetching hook is feeding the chart's data, instead of conditionally rendering Chart itself and losing its layout/sizing while the state changes.
<Chart type="line" data={data ?? []} x="month" series="value" isLoading={isLoading} error={fetchError && "Couldn't load data."} />All available props for Chart. See the full component page for an interactive playground.
| Prop | Type | Default | Description |
|---|---|---|---|
data | Row[] | { categories, series } | — | Row-based data array, or explicit categories/series (required). |
x | keyof Row | ((row: Row) => ChartCategory) | — | Category accessor, row-mode only. |
series | ChartSeriesDef<Row> | ChartSeriesDef<Row>[] | — | Series accessor(s), row-mode only. |
title / description | ReactNode | — | Chart heading text. |
ariaLabel | string | — | Accessible label for the chart. |
dataFormat | ChartDataFormatOptions | — | Value formatting (prefix/suffix/decimals) for labels/tooltips. |
showLabels | ChartShowLabelsOptions | — | Inline value-label visibility. |
data
Row[] | { categories, series }
Default: —
Row-based data array, or explicit categories/series (required).
x
keyof Row | ((row: Row) => ChartCategory)
Default: —
Category accessor, row-mode only.
series
ChartSeriesDef<Row> | ChartSeriesDef<Row>[]
Default: —
Series accessor(s), row-mode only.
title / description
ReactNode
Default: —
Chart heading text.
ariaLabel
string
Default: —
Accessible label for the chart.
dataFormat
ChartDataFormatOptions
Default: —
Value formatting (prefix/suffix/decimals) for labels/tooltips.
showLabels
ChartShowLabelsOptions
Default: —
Inline value-label visibility.
| Prop | Type | Default | Description |
|---|---|---|---|
type | "line" | "area" | "bar" | "column" | "pie" | "donut" | "heatmap" | — | Chart type (required). |
background | string | — | Chart background color. |
unstyled | boolean | false | Drop the built-in <figure> card frame (border / padding / radius / surface) — for a chart nested in a Card or a sparkline slot. |
palette | { colors?; colorShade?; roles? } | — | Series color palette overrides. |
line / bar / column / pieStyle / pie / heatmap | type-specific options | — | Per-type rendering options. pie: { center?: false, renderCenter?: ({total, formatted}) => ReactNode } for the donut hole. heatmap: { color, minOpacity, maxOpacity, domain, cellGap, cellRadius, showValues, emptyColor }. |
type
"line" | "area" | "bar" | "column" | "pie" | "donut" | "heatmap"
Default: —
Chart type (required).
background
string
Default: —
Chart background color.
unstyled
boolean
Default: false
Drop the built-in <figure> card frame (border / padding / radius / surface) — for a chart nested in a Card or a sparkline slot.
palette
{ colors?; colorShade?; roles? }
Default: —
Series color palette overrides.
line / bar / column / pieStyle / pie / heatmap
type-specific options
Default: —
Per-type rendering options. pie: { center?: false, renderCenter?: ({total, formatted}) => ReactNode } for the donut hole. heatmap: { color, minOpacity, maxOpacity, domain, cellGap, cellRadius, showValues, emptyColor }.
| Prop | Type | Default | Description |
|---|---|---|---|
height | number | 320 | Chart height in pixels. |
padding | { top?; right?; bottom?; left?: number } | — | Plot area padding. |
axis / axisX / axisY | ChartAxisOptions | — | Axis visibility + ticks. axisX/axisY take { show?, hide?, tickCount? } — `{ hide: true }` is an alias for `{ show: false }` (an explicit `show` wins). A custom `padding` on a labelled bar/column axis is floored so labels don't vanish. |
grid | ChartGridOptions | — | Gridline configuration. |
height
number
Default: 320
Chart height in pixels.
padding
{ top?; right?; bottom?; left?: number }
Default: —
Plot area padding.
axis / axisX / axisY
ChartAxisOptions
Default: —
Axis visibility + ticks. axisX/axisY take { show?, hide?, tickCount? } — `{ hide: true }` is an alias for `{ show: false }` (an explicit `show` wins). A custom `padding` on a labelled bar/column axis is floored so labels don't vanish.
grid
ChartGridOptions
Default: —
Gridline configuration.
| Prop | Type | Default | Description |
|---|---|---|---|
legend | boolean | ChartLegendOptions | true for multi-series | Legend visibility/position. |
tooltip | boolean | ChartTooltipOptions | true | Hover/focus tooltip visibility and formatting. |
zoom | false | { mode?: "x" | "xy"; wheel?; pan? } | — | Enables zoom/pan on axis charts. |
export | false | { formats?: ("svg" | "png")[]; filename? } | — | Enables an export action (SVG/PNG). |
fullscreen | false | { enabled?: boolean } | — | Enables a fullscreen toggle action. |
filters | false | ChartFiltersOptions<Row> | — | Enables interactive data filters. |
isLoading | boolean | — | Shows a loading state instead of the chart. |
error | ReactNode | — | Shows an error state instead of the chart. |
empty | ReactNode | — | Shown when data resolves to nothing plottable. |
legend
boolean | ChartLegendOptions
Default: true for multi-series
Legend visibility/position.
tooltip
boolean | ChartTooltipOptions
Default: true
Hover/focus tooltip visibility and formatting.
zoom
false | { mode?: "x" | "xy"; wheel?; pan? }
Default: —
Enables zoom/pan on axis charts.
export
false | { formats?: ("svg" | "png")[]; filename? }
Default: —
Enables an export action (SVG/PNG).
fullscreen
false | { enabled?: boolean }
Default: —
Enables a fullscreen toggle action.
filters
false | ChartFiltersOptions<Row>
Default: —
Enables interactive data filters.
isLoading
boolean
Default: —
Shows a loading state instead of the chart.
error
ReactNode
Default: —
Shows an error state instead of the chart.
empty
ReactNode
Default: —
Shown when data resolves to nothing plottable.
| Prop | Type | Default | Description |
|---|---|---|---|
onPointClick | (event: ChartPointEvent<Row>) => void | — | Called when a data point is clicked or activated via keyboard. |
onCellClick | (event: ChartHeatmapCellEvent<Row>) => void | — | type="heatmap" — a cell was clicked or keyboard-activated. |
onLegendChange | (hiddenSeriesIds: string[]) => void | — | Called when series visibility toggles via the legend. |
onSelectionChange | (selection: ChartSelection) => void | — | Called when a zoom/brush selection changes. |
onPointClick
(event: ChartPointEvent<Row>) => void
Default: —
Called when a data point is clicked or activated via keyboard.
onCellClick
(event: ChartHeatmapCellEvent<Row>) => void
Default: —
type="heatmap" — a cell was clicked or keyboard-activated.
onLegendChange
(hiddenSeriesIds: string[]) => void
Default: —
Called when series visibility toggles via the legend.
onSelectionChange
(selection: ChartSelection) => void
Default: —
Called when a zoom/brush selection changes.
| Prop | Type | Default | Description |
|---|---|---|---|
className / classNames / style | string / ChartClassNames / CSSProperties | — | Styling overrides (classNames covers base/header/title/description/actions/stage/svg/legend/filters). |
className / classNames / style
string / ChartClassNames / CSSProperties
Default: —
Styling overrides (classNames covers base/header/title/description/actions/stage/svg/legend/filters).