Web · Components
Chart
Chart: bar, line, area, pie, donut and scatter.
Live example
Preview
| ay | Revenue | Expenses |
|---|---|---|
| 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
Events
- Events appear here when you interact with the preview.
Zoom: 100,000 points, range navigator and the selected range
Zooming on categories: 36 months, the last 12 at first
| ay | Revenue | Expenses |
|---|---|---|
| Jan 24 | 42K | 36K |
| Feb 24 | 48.4K | 36.2K |
| Mar 24 | 53.1K | 35K |
| Apr 24 | 55K | 33.1K |
| May 24 | 54K | 31.1K |
| Jun 24 | 50.8K | 29.7K |
| Jul 24 | 47K | 29.5K |
| Aug 24 | 44.3K | 30.7K |
| Sep 24 | 44.2K | 33.3K |
| Oct 24 | 47.1K | 36.8K |
| Nov 24 | 52.5K | 40.7K |
| Dec 24 | 59.1K | 44.2K |
| Jan 25 | 65.1K | 46.6K |
| Feb 25 | 69K | 47.6K |
| Mar 25 | 70K | 47.1K |
| Apr 25 | 68.1K | 45.6K |
| May 25 | 64.5K | 43.5K |
| Jun 25 | 60.9K | 41.7K |
| Jul 25 | 58.9K | 40.7K |
| Aug 25 | 59.7K | 41.1K |
| Sep 25 | 63.5K | 43K |
| Oct 25 | 69.5K | 46K |
| Nov 25 | 76.1K | 49.8K |
| Dec 25 | 81.6K | 53.6K |
| Jan 26 | 84.6K | 56.7K |
| Feb 26 | 84.6K | 58.5K |
| Mar 26 | 82K | 58.8K |
| Apr 26 | 78.2K | 57.9K |
| May 26 | 75K | 56K |
| Jun 26 | 73.8K | 54K |
| Jul 26 | 75.6K | 52.4K |
| Aug 26 | 80.2K | 52K |
| Sep 26 | 86.6K | 53.1K |
| Oct 26 | 93K | 55.5K |
| Nov 26 | 97.8K | 58.9K |
| Dec 26 | 99.9K | 62.8K |
Inside a card: title, summary and bars + a line (target) together
Revenue and target
| ay | Revenue | Target |
|---|---|---|
| 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)
Horizontal bars, long names and value labels
| city | Sales |
|---|---|
| İstanbul | 1,840 |
| Ankara | 920 |
| İzmir | 760 |
| Bursa | 410 |
| Antalya | 380 |
Negative values: profit / loss
| ay | Net |
|---|---|
| Jan | 0 |
| Feb | 10.1K |
| Mar | 10.9K |
| Apr | 1.7K |
| May | -9.1K |
| Jun | -11.5K |
| Jul | -3.4K |
| Aug | 7.9K |
Import
Chart: bar, line, area, pie, donut and scatter. Works with its own SVG renderer; no external library. Colors come from the theme's --ui-chart-1 … --ui-chart-8 variables and change automatically in the dark theme.
- Easy to use: give the data and fields, the rest is computed: axis range, round ticks, abbreviated numbers (
12.5K), a time axis (day/month/year), thinning of overlapping labels. - Tooltip: on lines a vertical cursor snaps to the nearest x and lists all series; a band for bars, a slice for pies, the nearest point for scatter.
- Legend: appears automatically with multiple series; a click hides a series, hover brings it forward. Colors are tied to series; hiding one doesn't change the others' colors.
- Mobile: sliding your finger sideways on the chart makes the tooltip follow the values; vertical swipes scroll the page. Tapping elsewhere closes the tooltip.
- Accessibility: the chart is keyboard focusable; arrow keys move between values and the value is read to the screen reader. The data is also in a hidden table for screen readers.
- Performance: a single
<path>per series; a line with 100,000 points is reduced to the min/max of each pixel column (peaks aren't lost). Hover redraws only the cursor layer. - Next.js: a client component; on the server a fixed-height area and an accessible table are drawn, and the chart is painted once the width is measured (no layout shift).
Examples
A small chart showing a trend next to text or a number (no axes, no tooltip). A server component; needs no JavaScript and its width fits the container. Use Chart for interaction and axes.
Examples
ChartSeries
interfaceDetailed definition of a Chart series.
| Name | Type | Default | Description |
|---|---|---|---|
key | Key<T> | (string & {}) | Field the value is read from (e.g. "revenue"). The series id; must be unique. | |
label? | string | key | Name in the legend and tooltip. |
color? | ChartColor | its order in the palette | Color. See ChartColor. |
type? | ChartSeriesType | the chart's `type | Drawing type of this series; to show bars and lines together (e.g. revenue as bars, target as a line). |
value? | (row: T) => number | null | undefined | Reads the value from a function instead of a field (e.g. (r) => r.revenue - r.cost). | |
format? | ChartFormat | the chart's `format | Value format of this series. |
curve? | ChartCurve | the chart's `curve | Line style. |
dashed? | boolean | Dashed line (e.g. forecast, last year). | |
dots? | boolean | true` with few points | Show points on the line. |
hidden? | boolean | The series starts hidden; can be shown from the legend. |
ChartPoint
interfaceA data point; given in click events and the tooltip.
| Name | Type | Description |
|---|---|---|
row | T | The row itself. |
index | number | Index of the row in data. |
series | string | key of the series. |
value | number | null | Value (null = empty). |
ChartTooltipItem
interfaceA row in the tooltip. See ChartProps.renderTooltip.
| Name | Type | Description |
|---|---|---|
key | string | key of the series. |
label | string | Name of the series. |
color | string | Color of the series (CSS). |
value | number | null | Value (null = empty). |
formatted | string | Formatted value. |
share? | number | Share in a percent stack or a pie (0–1). |
ChartTooltipInfo
interfaceInfo given to the ChartProps.renderTooltip function.
| Name | Type | Description |
|---|---|---|
title | string | Title: the formatted x value; the slice name in a pie. |
row | T | undefined | The row (undefined for the "Other" slice). |
index | number | Index of the row in data (-1 for the "Other" slice). |
items | ChartTooltipItem[] | Values of the series. |
ChartRangeValue
typeValue of the ChartRange ends: an x value (category name, number or date).
ChartRange
typeVisible range: [start, end] x values.
- Time axis: a
Date, an ISO string ("2026-03-01") or ms. Events give aDate. - Number axis: numbers.
- Category (bar): x values of the categories at the ends; both included (e.g.
["Mar", "Jun"]).
ChartZoomOptions
interfaceDetailed settings of ChartProps.zoom.
| Name | Type | Default | Description |
|---|---|---|---|
brush? | boolean | false | Range navigator at the bottom: a small drawing of all the data. The visible window is dragged to scroll and narrowed with the handles at its edges; dragging on empty space selects a new range and a click goes to that point. |
brushHeight? | number | 48 | Height of the range navigator (px). |
wheel? | boolean | "ctrl" | "ctrl" | Zooming with the mouse wheel. - "ctrl": while Ctrl (⌘ on Mac) is held; the wheel alone scrolls the page and a short hint appears. Two-finger pinch on a touchpad also works this way. - true: always (for full-screen panels). - false: off. Horizontal scrolling (touchpad or Shift + wheel) pans the range while zoomed. |
select? | boolean | true | Zooming by dragging to select a range with the mouse. Shift + drag (or the middle button) pans. |
toolbar? | boolean | true | Zoom out / zoom in / reset buttons at the top right. Always visible while zoomed, otherwise on hover. |
ChartClassNames
interfaceClasses that can be given to the inner parts of Chart.
| Name | Type | Description |
|---|---|---|
plot? | string | Drawing area (a fixed-height box). |
legend? | string | Legend list. |
tooltip? | string | Tooltip box. |
toolbar? | string | Zoom buttons. |
brush? | string | Range navigator. |
ChartProps
interfaceProps of the Chart component.
Extends: Omit<ComponentProps<"figure">, "children" | "onSelect">
| Name | Type | Default | Description |
|---|---|---|---|
data | readonly T[] | Rows. For large data keep the array stable with useMemo. | |
type? | ChartType | "bar" | Chart type. - "bar": bars; horizontal with horizontal, stacked with stacked. - "line": lines; time series and trends. - "area": filled lines; share distribution with stacked. - "pie", "donut": parts of a whole; x is the slice name, series the value. - "scatter": scatter; x and the series value are numbers. |
x | Key<T> | ((row: T) => unknown) | Field of the x value (category, date or number). The slice name in a pie. Dates (Date or "2026-10-29") are drawn as a time axis. | |
series | Key<T> | readonly (Key<T> | ChartSeries<T>)[] | Values to draw: a single field ("revenue"), fields (["revenue", "cost"]) or detailed definitions (see ChartSeries). | |
label? | string | Screen reader name of the chart (e.g. "Monthly revenue"). Use Card for a visible title. | |
height? | number | 300 | Height of the drawing area (px). The width fits the container. |
stacked? | boolean | "percent" | Stacks bar and area series; a 100% stack with "percent". | |
horizontal? | boolean | Horizontal bars (for long category names). | |
curve? | ChartCurve | "smooth" | Line style: "smooth", "linear", "step". |
dots? | boolean | true` with few points | Show points on lines. |
legend? | boolean | "top" | "bottom" | "bottom"` with multiple series and for pies | Legend (series names). A click hides/shows a series, hover brings it forward. |
tooltip? | boolean | true | Tooltip showing values on hover, touch and keyboard. |
renderTooltip? | (info: ChartTooltipInfo<T>) => ReactNode | Draw the tooltip content yourself. | |
grid? | boolean | true | Horizontal grid lines. |
xAxis? | boolean | true | x axis labels (category names for horizontal bars). |
yAxis? | boolean | true | Value axis labels. |
xLabel? | string | Name of the x value; used in the header of the screen reader table (e.g. "Month"). | |
format? | ChartFormat | "number" | Value format (axis, tooltip, labels). See ChartFormat. |
xFormat? | ChartXFormat | Format of the x values. See ChartXFormat. | |
yMin? | number | Lower bound of the value axis. From the data when omitted (from 0 for bars). | |
yMax? | number | Upper bound of the value axis. | |
labels? | boolean | Value labels: at bar ends, at the line end, percentages on pie slices. Only those that fit are written. | |
references? | readonly ChartReference[] | Reference lines (target, average). See ChartReference. | |
colors? | readonly ChartColor[] | Colors used in order; by series (slice in a pie) order. | |
barSize? | number | 32 | Maximum bar thickness (px). |
center? | ReactNode | false | Center of a donut chart. Shows the total when omitted; hovering a slice shows that slice. Empty with false. | |
maxSlices? | number | 8 | Maximum slices in a pie; the rest are collected into "Other". |
loading? | boolean | Data is loading. With data the chart stays faded; without, a skeleton is drawn. | |
empty? | ReactNode | messages.chartEmpty | Content shown without data. |
animate? | boolean | true | Intro and data change animations. Off with the reduced motion preference. |
onPointClick? | (point: ChartPoint<T>) => void | When a value is clicked (tapped). | |
zoom? | boolean | ChartZoomOptions | Zoom and pan (on the x axis; the value axis fits the visible data automatically). Works for bar, line, area and scatter. - Mouse: drag to select a range; Ctrl/⌘ + wheel zooms at the pointer; Shift + drag or horizontal scrolling pans; double click resets. - Touch: pinch and pan with two fingers; double tap resets. One finger shows values as before, and vertical swipes scroll the page. - Keyboard: + / - zoom, 0 resets, Shift + arrow pans; when arrows move outside the visible window the range follows the value. - Range navigator: at the bottom with { brush: true } (see ChartZoomOptions). Smooth even at 100,000 points: while zoomed only the visible window is drawn and downsampling is done for that window (detail appears). | |
range? | ChartRange | null | Visible range (controlled). null is all data. Give it with onRangeChange. See ChartRange. | |
defaultRange? | ChartRange | Initial visible range (uncontrolled). | |
onRangeChange? | (range: ChartRange | null) => void | When the visible range changes; null when back to all. May be called every frame while zooming; defer expensive work. | |
locale? | string | {@link UIProvider} `locale | Number and date locale. |
currency? | string | {@link UIProvider} `currency | Currency. |
classNames? | ChartClassNames | Classes added to the inner parts. |
ChartFormat
typeFormat 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 theUIProvidercurrencysetting or the chart'scurrencyprop.Intl.NumberFormatOptions: Full control (e.g.{ style: "unit", unit: "kilogram" }).- Function: Your own format (e.g.
(v) =>${v} pcs``).
ChartXFormat
typeFormat 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.
ChartType
typeChart type. See ChartProps.type.
ChartSeriesType
typeHow a series is drawn. In bar and line charts it may differ per series.
ChartColor
typeColor: 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.
ChartReference
interfaceA horizontal or vertical reference line (target, average, limit).
| Name | Type | Default | Description |
|---|---|---|---|
value | number | Value of the line (on the y axis; on the value axis for horizontal bars). | |
label? | string | Short text next to the line (e.g. "Target"). | |
tone? | Tone | "neutral" | Color. |
ChartCurve
typeShape of the line between points.
SparklineProps
interfaceProps of the Sparkline component.
Extends: Omit<ComponentProps<"svg">, "children" | "color">
| Name | Type | Default | Description |
|---|---|---|---|
data | readonly (number | null | undefined)[] | Values; null is a gap. | |
type? | "line" | "area" | "bar" | "line" | Drawing type. |
color? | ChartColor | "chart-1" | Color. See ChartColor. |
height? | number | 32 | Height (px). The width fits the container. |
endDot? | boolean | true | Highlight the last value with a dot (line and area). |
label? | string | Screen reader text (e.g. "Last 12 months: rising"). Hidden when omitted. |