DitherCharts

Area chart

Updated

AreaChart draws one dithered area per series, overlapping, stacked, or stacked to fill the height, along a monotone, linear or step curve. Like every DitherCharts chart, it fills its container's width, animates in, moves a cursor with the arrow keys, and keeps a data table for screen readers.

Example

Area Chart

Desktop visitors, January to June

Area Chart

install command

npx dithercharts add area-chart

usage

import { AreaChart } from "@/components/dithercharts/area-chart"
import type { ChartConfig } from "@/components/dithercharts/chart-config"

const chartData = [
  { month: "Jan", desktop: 212 },
  { month: "Feb", desktop: 287 },
  { month: "Mar", desktop: 241 },
  { month: "Apr", desktop: 96 },
  { month: "May", desktop: 198 },
  { month: "Jun", desktop: 226 },
]

const chartConfig = {
  desktop: { label: "Desktop" },
} satisfies ChartConfig

export function AreaChartDefault() {
  return (
    <AreaChart
      data={chartData}
      config={chartConfig}
      xKey="month"
      label="Desktop visitors by month"
      height={220}
    />
  )
}

Installing needs DitherCharts Pro. See pricing.

Desktop visitors by month
monthDesktop
Jan212
Feb287
Mar241
Apr96
May198
Jun226
import { AreaChart } from "@/components/dithercharts/area-chart"
import type { ChartConfig } from "@/components/dithercharts/chart-config"

const chartData = [
  { month: "Jan", desktop: 212 },
  { month: "Feb", desktop: 287 },
  { month: "Mar", desktop: 241 },
  { month: "Apr", desktop: 96 },
  { month: "May", desktop: 198 },
  { month: "Jun", desktop: 226 },
]

const chartConfig = {
  desktop: { label: "Desktop" },
} satisfies ChartConfig

export function AreaChartDefault() {
  return (
    <AreaChart
      data={chartData}
      config={chartConfig}
      xKey="month"
      label="Desktop visitors by month"
      height={220}
    />
  )
}

Install

Charts install with DitherCharts Pro. See Installation to log in and import the stylesheet.

npx dithercharts add area-chart

Props

AreaChart props
PropTypeDefaultDescription
datarequiredType readonly ChartRow[]Default –One row per x position, left to right, e.g. { month: "Jan", desktop: 186, mobile: 80 }.
configrequiredType ChartConfigDefault –One entry per data key to plot, in draw order: its label and, optionally, its pattern.
xKeyrequiredType stringDefault –The row key that holds the x label, e.g. "month".
labelrequiredType stringDefault –Accessible name, e.g. "Monthly revenue". Also captions the table twin.
legendType booleanDefault falseA legend under the chart whose buttons show and hide series.
curveType "monotone" | "linear" | "step"Default "monotone"How the line runs between points.
fillType "solid" | "gradient"Default "solid"A flat 50% fill, or a fade from the top of the plot to the baseline.
yAxisType booleanDefault falseValue labels beside the grid lines.
stackType "none" | "stacked" | "expanded"Default "none"Series overlap, stack, or stack scaled to fill the height.
tooltipType TooltipOptionsDefault –The tooltip's indicator and label, and the x position it opens on at rest.
styleType StyleIdDefault "bayer4"Dither style.
animationType "develop" | "none"Default "develop"Entrance animation; reduced motion always shows the final frame.
heightType numberDefault 300Height in CSS pixels; the width fills the container.
cellType numberDefault 3Dither cell size in CSS pixels.
classNameType stringDefault –Classes on the chart's outer figure.

Styles

The dither styles style takes:

  • "bayer2"
  • "bayer4"
  • "bayer8"
  • "blue-noise"
  • "halftone"
  • "crosshatch"
  • "pixel"
  • "stipple"
  • "engraved"
  • "mezzotint"
  • "woodcut"
  • "floyd-steinberg"
  • "atkinson"
  • "riemersma"

Keyboard and accessibility

The chart is one Tab stop. Focusing it from the keyboard puts the cursor on the first point, or where the keys last left it; moving focus away clears it. The keys stop at the ends.

Chart keys
KeyAction
Left arrow Right arrowPrevious / next point
Home EndFirst / last point
Up arrow Down arrowPrevious / next series (2+ series)
EscapeDismiss the cursor

Screen readers

  • The chart's label names it, says how many points it has and lists these keys.
  • Each key press is announced in a polite live region. Moving the pointer is silent.
  • The table button under the chart shows its data as a table. Screen readers can reach the table even while it's hidden; clicking a row moves the cursor there and announces it.
  • With legend, each entry is a toggle button. The last one showing can't be hidden, but its button stays focusable.

On a touch screen, a tap pins the cursor and a tap outside the chart dismisses it.

See every area chart example