Skip to content

shadcn.io is an independent project built on shadcn/ui

Free

A line chart for React

One smooth desktop curve across six months, with no dots. Horizontal grid lines, and a tooltip for the hovered month.

One smooth curve of desktop visitors across six months, with no dots. Grid lines run horizontally. The tooltip shows the hovered month's count.

Use it for a trend where the shape matters more than each point. If people need the figures, put them in a Table. In React, Base UI does not draw the curve. You pass the months and the series color.

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.
Use email insteadNo credit card

Anatomy

Chart anatomy: container, grid, axis, bar, tooltip, legend

Usage

<div className="w-full max-w-xl rounded-md border bg-background p-4">
  <ChartContainer config={chartConfig}>
    <LineChart
      accessibilityLayer
      data={chartData}
      margin={{
        left: 12,
        right: 12,
      }}
    >
      <CartesianGrid vertical={false} />
      <XAxis
        axisLine={false}
        dataKey="month"
        tickFormatter={formatMonth}
        tickLine={false}
        tickMargin={8}
      />
      <ChartTooltip
        content={<ChartTooltipContent hideLabel />}
        cursor={false}
      />
      <Line
        dataKey="desktop"
        dot={false}
        stroke="var(--color-desktop)"
        strokeWidth={2}
        type="natural"
      />
    </LineChart>
  </ChartContainer>
</div>

FAQ

How does the line curve between months?

Line sets type to natural, so the stroke bends through the desktop points. dot is false, stroke is var(--color-desktop), and strokeWidth is 2.

Where does the stroke color come from?

config gives desktop the label Desktop and color var(--chart-1). ChartContainer exposes that as --color-desktop, which Line uses for stroke.

How are the month ticks shortened?

XAxis uses dataKey month and tickFormatter set to formatMonth, which keeps the first three characters. axisLine and tickLine are false, and tickMargin is 8.

What are the side margins for?

LineChart sets margin to 12 on the left and right, so the curve doesn't sit on the frame edge. CartesianGrid sets vertical to false.

What does the tooltip show?

ChartTooltipContent sets hideLabel, and cursor is false. The row is the Desktop series from config, for the hovered month.

Can I move along the line with the keyboard?

Yes. LineChart sets accessibilityLayer. The points are January through June, with desktop values 186, 305, 237, 73, 209, and 214.

API Reference

Chart

Sets config={chartConfig} and hideLabel. The rest is on the Chart page.