shadcn.io is not affiliated with official shadcn/ui
About
Use it to compare how two series move over the same months: where they cross, which one leads, whether they rise together. Lines can overlap without hiding each other, unlike stacked areas, so the gap between them reads directly. Past four lines the colors blur; the interactive version shows one at a time instead.
Two monotone curves share one set of months and one value scale, each in its own color, without dots until you hover: then both lines get a dot at that month. The tooltip shows the month and then one row per series, each with a dot in that series' color.
Installation
Usage
import { ChartLineMultiple } from "@/components/charts/chart-line-multiple";<ChartLineMultiple />Customize
- Two
<Line>elements share<LineChart data={chartData}>:dataKey="desktop"anddataKey="mobile", each stroked with its ownvar(--color-<key>). type="monotone"keeps each curve from overshooting its points, anddot={false}leaves clean strokes.- JSX order is paint order: the second
<Line>draws over the first where they cross. <ChartTooltipContent />with no props shows the month and one row per line, in the order the lines are declared.
FAQ
How do I add a third line?
Add the field to every row, a tablet entry in chartConfig with var(--chart-3), and a third <Line dataKey="tablet" stroke="var(--color-tablet)" />.
Why are the curves monotone here?
type="monotone" never bends past a point, so neither line suggests a peak or a dip that isn't in the data. With two lines close together, natural can overshoot and make them seem to cross when they don't. Change type on each <Line> to try another shape.
How do I show which line is which?
Add <ChartLegend content={<ChartLegendContent />} /> inside <LineChart>. It reads the labels and colors from chartConfig; verticalAlign="top" moves it above the plot.
What if the two series use different units?
Add a second <YAxis yAxisId="right" orientation="right" /> and set yAxisId on each <Line> to its axis. Label both, since two axes make it easy to compare things that aren't comparable. Two small charts are often clearer.
API Reference
ChartContainer
configChartConfig
Each series by its data key: its label, an icon, and a color (or a * theme color per light and dark), read by the tooltip and legend and set * as --color-<key>.
initialDimension?{ height: number; width: number; }
The size it renders at before it's measured, so the first paint isn't * empty.
- Type
{ height: number; width: number; }- Default
INITIAL_DIMENSION
className?string
Merged with the part's classes.
ChartLegend
ChartLegendContent
<div>
hideIcon?boolean
Hides each series' icon (from config), leaving its color swatch.
- Default
false
nameKey?string
The key in each legend item's data to look its label up by in config. * Defaults to the item's dataKey.
className?string
Merged with the part's classes.
ChartStyle
<style>
configChartConfig
The chart config whose colors it writes as --color-<key> variables.
idstring
The element's id.
ChartTooltip
ChartTooltipContent
<div>
hideIndicator?boolean
Hides each item's color indicator.
- Default
false
hideLabel?boolean
Hides the tooltip's label, the hovered point's.
- Default
false
indicator?"dashed" | "dot" | "line"
The color indicator's shape: a dot, a line or dashed.
- Type
"dashed" | "dot" | "line"- Default
"dot"
labelFormatter?(label: any, payload: TooltipPayload) → React.ReactNode
Formats the tooltip's label; its value is untyped, as in recharts 3.8.
- Type
(label: any, payload: TooltipPayload) → React.ReactNode- Parameters
label– anypayload– TooltipPayload- Returns
React.ReactNode
labelKey?string
The key in the data to read the label from, looked up in config.
nameKey?string
The key in each item's data to look its name up by in config.
className?string
Merged with the part's classes.
Related
Interactive Line Chart
Line chartsThree months of daily values, switched between two series.
Line Chart
Line chartsOne series as a smooth line over six months.
Stacked Area Chart
Area chartsTwo series stacked into one total, each band its own color.
Multiple Bar Chart
Bar chartsTwo series grouped side by side for each month.
Multiple Radar Chart
Radar chartsTwo series overlaid on the same radar grid.
Linear Line Chart
Line chartsStraight segments between points, no smoothing.