Skip to content
nexubDesign System
v11.9.0

Components · Data Display

Line Chart

BetaAdded v3.2.0

Show a trend over ordered categories such as time. Server-rendered SVG on the chart palette.

import { LineChart } from '@nexub/react';
View as Markdown

Playground

Props

size
legend
Weekly users
weekActiveTrial
W1820310
W2870290
W3905340
W4960330
W51,010360
W61,080355
TSX
<LineChart className="w-full" data={data} index="week" series={…} title="Weekly users" />

Examples

Two series

Weekly users
weekActiveTrial
W1820310
W2870290
W3905340
W4960330
W51,010360
W61,080355

Area

API latency, p95
dayp95 latency
Mon210 ms
Tue190 ms
Wed240 ms
Thu205 ms
Fri180 ms

Gaps and one currency per series

Revenue by currency
monthUSDMYR
Jan$12,400RM 31,000
Feb$13,100—
Mar—RM 35,500
Apr$15,800RM 38,200
Show as table
Revenue by currency
monthUSDMYR
Jan$12,400RM 31,000
Feb$13,100—
Mar—RM 35,500
Apr$15,800RM 38,200

States

  • Weekly users
    weekActiveTrial
    W1820310
    W2870290
    W3905340
    W4960330
    W51,010360
    W61,080355
    default
  • loading
  • Weekly users
    weekActiveTrial
    W1820310
    W2870290
    W3905340
    W4960330
    W51,010360
    W61,080355
    size="sm"
  • Weekly users
    weekActiveTrial
    W1820310
    W2870290
    W3905340
    W4960330
    W51,010360
    W61,080355
    size="md"
  • Weekly users
    weekActiveTrial
    W1820310
    W2870290
    W3905340
    W4960330
    W51,010360
    W61,080355
    size="lg"

Props

Props
PropTypeDefaultDescription
titlerequiredstring—Accessible name of the chart and caption of its data table.
datarequiredT[]—One row per category, in order.
indexrequiredkeyof T & string—Key of the category label in each row (the x axis).
seriesrequiredChartSeries[]—{ key, label?, color? } per series. color is 1–8 from the categorical chart palette; defaults to the series position.
valueFormat((value: number) => string)defaultFormatFormats axis labels, hover text and the data table.
size'sm' | 'md' | 'lg''md'Plot height: 8, 12 or 16rem.
legendfalse | true | 'toggle'trueShow the legend. Defaults to on for more than one series.
areabooleanfalseFill the area under each line.
series[].color1–8 | 'good' | 'warning' | 'danger' | 'neutral'—11.3: a palette colour or a semantic tone.
series[].valueFormat(value: number) => string—11.3: formats this series in the tooltip and table (one currency per series).
integerTicksboolean—11.3: gridlines on whole numbers only (counts). Also 11.3: a null or missing value is drawn as a gap (no bar, a break in the line) and listed as "—", not counted as 0.
tableViewstring | boolean—11.3: a visible "Show as table" disclosure with the same data. Works without JS.
defaultHiddenSeriesstring[]—Keys of the series hidden at first.
emptyStateReact.ReactNode—Shown when there is no data. Defaults to the "no data" message.
errorStateReact.ReactNode—Shown in place of the data when a load failed, for example an ErrorState with a retry action. Wins over loading and empty.
hiddenSeriesstring[]—Keys of the hidden series, controlled (10.7).
interactiveboolean—A crosshair and tooltip that follow the pointer, and arrow-key navigation between points.
loadingboolean—Shows a skeleton in place of the data and sets aria-busy.
onHiddenSeriesChange((hidden: string[]) => void)—
onPointClick((point: ChartPoint<T>) => void)—Click, tap, or Enter/Space on a point. Turns interactive on unless it is set to false.

Accessibility

Screen reader

  • The chart is a `figure` named by `title`. The drawing is hidden from assistive tech; a visually hidden table carries every value.

  • Colour is never the only cue: the legend and table name each series. Past six series, label directly or group the rest as "Other".

On iOS & Android