Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Chart examples · Line

A line chart with dots and colors for React

A line chart whose dots take each browser's color from the data.

Framework
UI library

Use it when each point belongs to a category with its own color. The line is one stroke in the series color, and the dot function draws each point's dot in the fill its data row carries, one color per browser.

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 each dot get its own color?

Line sets dot to renderDot. That function renders a Dot with r 5, and both fill and stroke set to payload.fill. key is payload.browser.

Where does payload.fill come from?

Each row sets fill to a variable such as var(--color-chrome). config maps chrome, safari, firefox, edge, and other to --chart-1 through --chart-5 and to labels like Chrome.

What color is the stroke between the dots?

Line sets stroke to var(--color-visitors), strokeWidth to 2, type to natural, and dataKey to visitors. config gives visitors the color var(--chart-2) and the label Visitors. The browser colors are the dot fill values.

Why is the chart padded on the top and sides?

LineChart sets margin to 24 on the top, left, and right. There is no XAxis in this file. CartesianGrid sets vertical to false.

What does the tooltip show?

ChartTooltipContent sets hideLabel, indicator to line, and nameKey to visitors. cursor is false. The row is named Visitors from config, and the value is that point's visitors count.

Does the keyboard reach the points?

Yes. LineChart sets accessibilityLayer. The browser key is on each row, and config holds the matching label. The counts are 275, 200, 187, 173, and 90.