shadcn.io is not affiliated with official shadcn/ui
Chart examples · Line
A multiple line chart for React
A line chart comparing desktop and mobile visitors as two lines.
Use it to compare two trends on one scale. Desktop and mobile are two monotone lines sharing the same axes, and the tooltip lists both values for the hovered month.
Preview
Installation
FAQ
How are the two lines drawn?
The chart renders two Line components. Both set type to monotone, dot to false, and strokeWidth to 2. One uses dataKey desktop and stroke var(--color-desktop). The other uses dataKey mobile and stroke var(--color-mobile).
Where do the line colors come from?
config maps desktop to var(--chart-1) and the label Desktop, and mobile to var(--chart-2) and the label Mobile. ChartContainer exposes those as --color-desktop and --color-mobile.
How are the months abbreviated?
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.
Does the tooltip list both series?
Yes. ChartTooltip renders ChartTooltipContent with cursor set to false. The title is the month, and the rows are Desktop and Mobile from config.
Related
- A line chartA line chart drawing one series as a
- A stacked area chartAn area chart stacking desktop and mobile
- A multiple bar chartA bar chart grouping desktop and mobile
- An interactive line chartA line chart of three months of daily
- A line chart with dotsA line chart with a dot on every data
- An area chart with a legendA stacked area chart of desktop and