Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Chart examples · Line

A line chart with custom dots for React

A line chart that draws each data point as an icon instead of a dot.

Framework
UI library

Use it when the points mean something, like commits along a timeline. The dot prop takes a function that draws a Lucide icon centered on each point, stroked in the series color and filled with the background so the line doesn't show through.

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 drawn as icons?

Line sets dot to renderDot, which returns a GitCommitVerticalIcon centered on the point. DOT_SIZE is 24, and x and y are cx and cy minus half of that size.

How is the icon colored?

The icon sets stroke to var(--color-desktop), className to fill-background, and aria-hidden to true. width and height are both DOT_SIZE. key is payload.month.

What does the line itself use?

Line uses dataKey desktop, type natural, stroke var(--color-desktop), and strokeWidth 2. config maps desktop to var(--chart-1) and the label Desktop.

How are the month ticks shortened?

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

What does the tooltip show?

ChartTooltipContent sets hideLabel, and cursor is false. The row is the Desktop value from config. The icon is marked aria-hidden.

Can I move along the line with the keyboard?

Yes. LineChart sets accessibilityLayer. CartesianGrid sets vertical to false. The rows also include mobile, and the only Line reads desktop.