Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Charts

Free

Linear Area Chart

One series joined by straight segments instead of a curve, so every bend sits on a real data point. A monthly area chart for React.

Framework
Charting library

Preview

Preview width

About

Use it when the data was measured at those months and nothing is known in between: a closing price, a monthly count, a reading. The smooth area looks softer but can bulge above or below the data. For values that hold flat between changes, use the step area.

Six monthly values are joined by straight lines with a 40% fill, so every corner is a data point. The tooltip leaves the month out and marks Desktop with a dot.

Installation

Sign in to get your install command
Free with an account. It carries your token, so the CLI installs everything in one go.

Usage

import { ChartAreaLinear } from "@/components/charts/chart-area-linear";
<ChartAreaLinear />

Customize

  • type="linear" on <Area> draws straight segments between points.
  • <ChartTooltipContent hideLabel indicator="dot" /> shows the row without the month.
  • fill and stroke read var(--color-desktop) with fillOpacity={0.4}.
  • <CartesianGrid vertical={false} /> and an <XAxis> without line or ticks keep the frame quiet.

FAQ

When should I pick straight segments over a curve?

When people might read values between the labeled months, or when a curve's overshoot would mislead: finance, measurements, anything someone checks. A smooth curve can bulge above the highest point; straight segments never leave the data.

How do I switch it back to a smooth curve?

Set type="natural" on <Area>, or monotone for a curve that bends without overshooting any point.

How do I add a dot at each corner?

Set dot on <Area>, or activeDot for the hovered point only. The Line Chart with Dots shows the styling.

What does the tooltip show?

Only the series row: <ChartTooltipContent hideLabel indicator="dot" />. Drop hideLabel to show the month above it.

How does a screen reader read it?

accessibilityLayer makes the chart focusable and moves the tooltip with the arrow keys, but shadcn's tooltip content isn't a live region, so the values aren't announced. Keep the card's title and description: they say what the chart shows.

API Reference

ChartContainer

PropType
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>

PropType
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>

PropType
configChartConfig

The chart config whose colors it writes as --color-<key> variables.

idstring

The element's id.

ChartTooltip

ChartTooltipContent

<div>

PropType
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 – any

payload – 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.