Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Chart examples · Line

A line chart with step for React

A line chart with step interpolation, drawing flat runs and vertical jumps.

Framework
UI library

Use step lines for values that hold until they change, like prices, plan limits or stock levels. type="step" draws flat runs between months joined by vertical jumps, with no dots.

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 get its staircase shape?

Line sets type to step. The stroke runs flat at each desktop value, then jumps vertically to the next month. dot is false, stroke is var(--color-desktop), and strokeWidth is 2.

Where does the stroke color come from?

config sets desktop to the label Desktop and color var(--chart-1). ChartContainer turns that into --color-desktop for the stroke.

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 is drawn behind the steps?

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 value for the hovered month.

Which values do the steps connect?

desktop is 186, 305, 237, 73, 209, and 214 from January through June. type step uses those points as the corners of the stairs.