shadcn.io is not affiliated with official shadcn/ui
About
Pick it over the smooth line when the readings are all you know: monthly snapshots, prices, counts. Straight segments promise nothing between two months, while a curve can bulge above the highest reading. The corners also make each month easy to find without dots.
Six monthly values joined by straight strokes, over horizontal grid lines, with three-letter months below. The tooltip shows the value without the month.
Installation
Usage
import { ChartLineLinear } from "@/components/charts/chart-line-linear";<ChartLineLinear />Customize
type="linear"on<Line>joins the points with straight segments; that prop is the whole difference from the Line Chart.dot={false}hides the markers. Setdotto an object such as{ fill: "var(--color-desktop)" }to show them.stroke="var(--color-desktop)"reads the variableChartContainerwrites fromchartConfig, atstrokeWidth={2}.<ChartTooltipContent hideLabel />shows the value alone, andcursor={false}drops the hover cursor.
FAQ
When should I use straight segments instead of a curve?
When the points are measurements and nothing is known between them: prices, inventory, survey results. A natural curve rounds every turn and can bulge past a point, which reads as a value that never happened. Curves suit overviews where the general shape matters more than each reading.
How do I get sharp corners?
Recharts draws the path with SVG's default miter joins, so the corners are already sharp. Pass strokeLinejoin="round" to <Line> to soften them.
How do I mark each reading?
Replace dot={false} with an object, dot={{ fill: "var(--color-desktop)", r: 4 }}, and add activeDot={{ r: 6 }} to grow the hovered one, as the Line Chart with Dots does.
What happens with a missing month?
A null value breaks the line by default. Set connectNulls on <Line> to draw straight across the gap instead.
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
Line Chart
Line chartsOne series as a smooth line over six months.
Step Line Chart
Line chartsA stepped line for values that hold until they change.
Linear Area Chart
Area chartsStraight segments between points, no curve smoothing.
Line Chart with Dots
Line chartsA line with a dot on every data point.
Bar Chart
Bar chartsOne series of rounded vertical bars, a month each.
Multiple Line Chart
Line chartsTwo series as lines on the same axes.