Skip to content

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

Free

A linear area chart for Ark UI

Desktop visitors as a filled area with straight edges between months, not a curve. The fill is the series color, partly see-through.

Six months of desktop visitors, joined by straight edges and filled with the series color at partial strength. Nothing is curved between the points.

Use straight edges when a curve would suggest values between months that were never measured. A step fits values that hold flat. For the numbers, use a Table. In React, Ark UI does not choose the straight edges. You set the area type.

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}>
    <AreaChart
      accessibilityLayer
      data={chartData}
      margin={{
        left: 12,
        right: 12,
      }}
    >
      <CartesianGrid vertical={false} />
      <XAxis
        axisLine={false}
        dataKey="month"
        tickFormatter={formatMonth}
        tickLine={false}
        tickMargin={8}
      />
      <ChartTooltip content={renderTooltipContent} cursor={false} />
      <Area
        dataKey="desktop"
        fill="var(--color-desktop)"
        fillOpacity={0.4}
        stroke="var(--color-desktop)"
        type="linear"
      />
    </AreaChart>
  </ChartContainer>
</div>

FAQ

How are the edges straight?

Area sets type to linear, so each month joins the next with a straight segment. dataKey is desktop, stroke and fill are var(--color-desktop), and fillOpacity is 0.4.

Where does the fill color come from?

config gives desktop the label Desktop and color var(--chart-1). ChartContainer exposes it as --color-desktop, which both fill and stroke use.

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.

What grid is behind the area?

CartesianGrid sets vertical to false. AreaChart sets accessibilityLayer, so the points can be reached from the keyboard.

What does the tooltip show?

ChartTooltipContent sets hideLabel and indicator to dot. cursor is false. The row is named Desktop from config.

Which months are filled?

The series is January through June: desktop is 186, 305, 237, 73, 209, and 214. The area fills from the straight segments between those points down to the baseline.

API Reference

Chart

Sets config={chartConfig}, content={renderTooltipContent} and cursor={false}. The rest is on the Chart page.