Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Chart examples · Line

A line chart with dots for React

A line chart with a dot on every data point and a larger dot on hover.

Framework
UI library

Use it when readers need to find the exact months along a trend. The line is a smooth curve with a dot on every point, and the hovered point grows into a larger active dot.

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 are the dots turned on?

Line sets dot to an object whose fill is var(--color-desktop). activeDot is { r: 6 }, so the hovered point is drawn at radius 6. dataKey is desktop, type is natural, and strokeWidth is 2.

Where does the line color come from?

config sets desktop to the label Desktop and color var(--chart-1). Line uses that same var(--color-desktop) for stroke and for the dot fill.

How are the months abbreviated?

XAxis uses dataKey month and tickFormatter set to formatMonth, which returns value.slice(0, 3). axisLine and tickLine are false, tickMargin is 8, and the side margins are 12.

What grid is behind the line?

CartesianGrid sets vertical to false. LineChart sets accessibilityLayer, so the points can be reached from the keyboard.

What does the tooltip show?

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

Is the mobile field drawn?

No. The rows include mobile, and config gives it the label Mobile and color var(--chart-2). The only Line uses dataKey desktop.