Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Chart examples · Line

A line chart with a label for React

A line chart with a dot on each point and its value printed above it.

Framework
UI library

Use it when the exact values should be on the chart, not only in the tooltip. The line has a dot on each month and a LabelList above it printing the value, with a top margin so the highest label isn't clipped.

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 is the number printed above each point?

Line wraps a LabelList with position top, offset 12, fontSize 12, and className fill-foreground. The list has no dataKey, so the text is the line's desktop value.

Why is there room above the line?

LineChart sets margin to { top: 20, left: 12, right: 12 }. The top inset keeps labels such as February's 305 inside the container.

How are the dots drawn?

Line sets dot to an object whose fill is var(--color-desktop), and activeDot to { r: 6 }. type is natural, stroke is var(--color-desktop), and strokeWidth is 2.

How are the months abbreviated?

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

What does the tooltip show?

ChartTooltipContent sets indicator to line, and cursor is false. The month stays as the tooltip title, and the row is named Desktop from config.

Which series is actually drawn?

Line uses dataKey desktop. config also names mobile with color var(--chart-2), and the rows include mobile, but this file adds no second Line. LineChart sets accessibilityLayer.