Skip to content

React Line Chart

An animated React line chart with end labels, a crosshair tooltip you can drive with the arrow keys, and a table view of the same data. Pass data as readonly ChartRow[]: one object per point: the index key plus one number per series key.

npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/line-chart.json

Monthly revenue by channel

  • Organic
  • Paid
  • Referral
Use left and right arrow keys to read values.

  • LineChart
  • LineTable
  • PREVIOUS_SERIES_KEY
  • defaultLineChartLabels
  • +2 more

Line chart with three series

Hover or press the arrow keys to read a month. Click a legend key to hide a series; the axis re-fits.

Monthly revenue by channel

In US dollars

  • Organic
  • Paid
  • Referral

Files to copy

11 folders · 28 files · 4 packages
From theme/src/
  • components/charts/{line-chart.tsx, chart-annotations.tsx, chart-brush.tsx, chart-export-menu.tsx, chart-export.ts, chart-figure.tsx, chart-fit.tsx, chart-icons.tsx, chart-parts.tsx, chart-patterns.tsx, chart-sync.tsx, chart-utils.ts}
  • components/charts/chart-parts/
  • components/drawer/parts/sheet.tsx
  • components/kbd/
  • components/menu/
  • components/skeleton/
  • components/status-icons/
  • hooks/{use-controllable.ts, use-intersection.ts, use-latest.ts, use-media-query.ts, use-preferences.ts}
  • motion/tokens.ts
  • lib/{cn.ts, csv.ts, form.ts, glide-highlight.tsx, heading.ts, math.ts, popup-a11y.ts, popup-motion.ts, warn-once.ts}
  • styles/
shadcn CLI
npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/line-chart.jsonRegistry item: line-chart. The styles need the Tailwind v4 glass UI setup.
Packages
pnpm add @base-ui/react clsx motion tailwind-merge

Next.js: samples here pass functions (formatters, seriesLegend, a dashboard's load), so put them in a file that starts with "use client".

LineChart props

PropTypeDefaultDescription
data (required)readonly ChartRow[]NoneOne object per point: the index key plus one number per series key, e.g. { month: "Jan", visits: 4200 }.
index (required)stringNoneKey of the x-axis value in each row (e.g. "month").
series (required)readonly CompareSeries[]NoneThe lines. color is a palette slot 1–8. Give a series a compareKey to draw its previous period from that key of each row as a dashed, muted line.
areabooleanfalseFill the area under each line with a gradient that fades to transparent.
heightnumber260Height of the chart in px; the width follows the container.
format((n: number) => string)NoneFormat values in the tooltip, labels and on the axis. Without it, values use formatCompact (or the locale's compact format) and axis ticks get exactly as many decimals as their step needs.
localestringNoneLocale for the default number format (e.g. "de").
endLabelsbooleantrueLabel the end of each line (only when labels don't collide; the legend always carries identity).
emptyStateReactNodeNoneShown when there is nothing to plot.
curveChartCurve"monotone""monotone" (default): smooth curves that never overshoot a value. "linear": straight segments.
gradientbooleantrueArea fill fades from the line to transparent (default). false: a flat soft wash.
zerobooleantrueKeep zero on the value axis (default). false fits the axis to the data, for values that live far from zero (rates, prices, temperatures). Areas then fill to the bottom of the plot.
glowbooleantrueSoft glow on the active line and point in dark mode.
patternsbooleantrue when series.length > 3Tell series apart without colour: each series gets its own marker shape (circle, square, triangle, diamond).
hiddenSeriesreadonly string[]NoneSeries keys to hide (controlled). Inside a ChartCard the card's legend controls this.
highlightedSeriesstring | nullNoneSeries key to emphasise (the others dim). Inside a ChartCard, legend hover controls this.
annotationsreadonly ChartAnnotation[][]Reference lines and bands, event markers and ranges.
brushboolean | LineChartBrushNoneA range selector under the chart for long series (drag, keyboard, touch).
syncbooleantrueInside a ChartSyncProvider: share the crosshair with the other charts.
liveboolean | { duration?: number; }off; an object's duration defaults to 0.6 inside the slide hookStreaming data: when the rows slide by (oldest out, newest in), the lines slide left instead of morphing. Pair with useLiveData(). duration = seconds per slide (default 0.6).
tooltipSurfaceTooltipSurface"glass"Tooltip surface: "glass" (default) or "opaque" for busy charts.
labelsPartial<LineChartLabels>defaultLineChartLabelsThe chart's built-in strings (empty state, table text); a partial object over the English defaults, so pass only the keys you translate. Every other string, for translation: labels={{ instructions: "…" }}; omitted keys keep the English of defaultLineChartLabels. All 3 keys of LineChartLabels are listed in the key table under the props table.
aria-label (required)stringNoneAccessible summary of what the chart shows.
classNamestringNoneAdds extra classes to the outer element.
LineChartLabels keys and English defaults (3)
Pass any key in labels; the rest keep the defaults of defaultLineChartLabels.
KeyEnglish default
instructionsUse left and right arrow keys to read values.
previous(label) => `${label} (previous)`
brushnested object: takes the keys of ChartBrushLabels; empty here, so its own English defaults apply

LineTable props

PropTypeDefaultDescription
data (required)readonly ChartRow[]NoneThe rows to show: one object per row, holding the index key and one number per series key.
index (required)stringNoneThe key in each row that names the row, such as "month". It becomes the first column.
series (required)readonly CompareSeries[]NoneSeries to list as columns; one with a compareKey also gets a previous-period column.
format((n: number) => string)formatCompactFormats each number in the table cells.
indexLabelstringNoneHeader of the first column; the index key when left out.
captionstringNoneVisually hidden caption naming the table for screen readers.
labelsPartial<ChartTableLabels>defaultChartTableLabelsText for i18n (defaults come from the enclosing ChartCard's labels, else English). Every other string, for translation: labels={{ noData: "…" }}; omitted keys keep the English of defaultChartTableLabels. All 2 keys of ChartTableLabels are listed in the key table under the props table.
ChartTableLabels keys and English defaults (2)
Pass any key in labels; the rest keep the defaults of defaultChartTableLabels.
KeyEnglish default
noDataNo data
previous(label: string) => `${label} (previous)`

When to use a line chart

Use a React line chart when the question is how a number changes over time: revenue by month, requests per second, sign-ups per week. The eye follows the slope, so a line makes trends, turning points and seasonality easy to read, and several series can share one axis without hiding each other. If you are weighing a shadcn line chart alternative, this one adds a keyboard-readable data table, a legend and the same glass styling as the other charts.

Prefer a bar chart when you compare separate categories, and an area chart when the filled volume matters. For a continuous feed, the streaming chart slides new points in. A line chart in a stat tile can shrink to a sparkline. See also the React area chart, the React bar chart and the real-time chart, or browse all animated React charts.

Frequently asked questions

All exports on this page

  • LineChart — A multi-series line chart for trends over time or any ordered axis, with optional area wash, previous-period lines, annotations.
  • LineTable — The table view of a LineChart or an AreaChart: one row per point on the x axis.
  • PREVIOUS_SERIES_KEY — Legend key that hides / shows every previous-period (comparison) line at once.
  • defaultLineChartLabels — The built-in English strings of LineChart; spread it into your own labels and change what you need.

Keyboard

KeysAction
TabMove through the Chart / Table tabs, then the legend keys, then the chart itself.
← → (↑ ↓)Read the previous or next point; the values are announced.
Home/EndJump to the first or last point.
EscapeClear the active point.
Enter/Spaceon a legend keyHide or show that series.

Accessibility

  • Tab focuses the chart as one stop; the arrow keys move a crosshair one point at a time and announce the x value with every series value.
  • The Chart / Table tabs switch to a LineTable: one row per x value, one column per series, with a caption and row headers.
  • With more than three series (or patterns), each line gets its own dash rhythm and marker shape, so no series depends on hue.
  • Reduced motion: lines appear at their final shape and data changes jump; live data stops sliding.

48 charts pages in all: browse them on Charts.

By Lokendra Singh Rathore (GitHub, opens in a new tab). Published , updated .