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.jsonMonthly revenue by channel
- Organic
- Paid
- Referral
LineChartLineTablePREVIOUS_SERIES_KEYdefaultLineChartLabels- +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
import { ChartCard } from "@/components/sheenui/charts/chart-parts/chart-card";
import { ChartTable } from "@/components/sheenui/charts/chart-parts/empty-table";
import { seriesLegend } from "@/components/sheenui/charts/chart-parts/legend-tooltip";
import { formatCompact, type ChartSeries } from "@/components/sheenui/charts/chart-utils";
import { LineChart } from "@/components/sheenui/charts/line-chart";
// Package build (after the first npm release, or a packed tarball): import { ChartCard, ChartTable, LineChart, formatCompact, seriesLegend, type ChartSeries } from "@sheenui/theme";
const usd = (n: number) => "$" + formatCompact(n);
const data = [
{ month: "Jan", organic: 4200, paid: 2100, referral: 900 },
{ month: "Feb", organic: 4800, paid: 2300, referral: 1100 },
{ month: "Mar", organic: 5600, paid: 2200, referral: 1250 },
];
const series: ChartSeries[] = [
{ key: "organic", label: "Organic", color: 1 },
{ key: "paid", label: "Paid", color: 2 },
{ key: "referral", label: "Referral", color: 3 },
];
export function Example() {
return (
<ChartCard
title="Monthly revenue by channel"
legend={seriesLegend(series, "line")}
table={<ChartTable data={data} index="month" series={series} format={usd} />}
>
<LineChart data={data} index="month" series={series} format={usd} aria-label="Monthly revenue by channel" />
</ChartCard>
);
}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.tsxcomponents/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.tslib/{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
LineChartLabels keys and English defaults (3)
LineTable props
ChartTableLabels keys and English defaults (2)
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
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.
Related pages
48 charts pages in all: browse them on Charts.
By Lokendra Singh Rathore (GitHub, opens in a new tab). Published , updated .