Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Chart examples · Line

A line chart for React

A line chart drawing one series as a smooth curve across six months.

Framework
UI library

The starting point for showing a trend over time. One series is drawn as a smooth natural curve across six months, without dots, over horizontal grid lines; the tooltip shows the hovered month's value.

Preview

Preview width

Installation

Sign in to get your install command
Free with an account. It carries your token, so the CLI installs everything in one go.

FAQ

How does the line curve between months?

Line sets type to natural, so the stroke bends through the desktop points. dot is false, stroke is var(--color-desktop), and strokeWidth is 2.

Where does the stroke color come from?

config gives desktop the label Desktop and color var(--chart-1). ChartContainer exposes that as --color-desktop, which Line uses for stroke.

How are the month ticks shortened?

XAxis uses dataKey month and tickFormatter set to formatMonth, which keeps the first three characters. axisLine and tickLine are false, and tickMargin is 8.

What are the side margins for?

LineChart sets margin to 12 on the left and right, so the curve doesn't sit on the frame edge. CartesianGrid sets vertical to false.

What does the tooltip show?

ChartTooltipContent sets hideLabel, and cursor is false. The row is the Desktop series from config, for the hovered month.

Can I move along the line with the keyboard?

Yes. LineChart sets accessibilityLayer. The points are January through June, with desktop values 186, 305, 237, 73, 209, and 214.