Area Chart

v0.2.2

Fully presentational area chart widget using Recharts. Supports multiple areas, stacked areas, custom curve types, fill opacity control, and responsive design.

View as Markdown

Install

npx shadcn@latest add @signalos/area-chart

Requires a configured @signalos registry and a valid SIGNALOS_REGISTRY_TOKEN - get access. Registry dependencies (@signalos/tokens, @signalos/chart-core) are pulled automatically.

Preview

Example & code

area-chart.example.tsx
import { AreaChart } from "@/components/widgets/area-chart/AreaChart"

const data = [
  { month: "Jan", visitors: 4000, pageviews: 6400 },
  { month: "Feb", visitors: 3000, pageviews: 5398 },
  { month: "Mar", visitors: 2000, pageviews: 4800 },
  { month: "Apr", visitors: 2780, pageviews: 5908 },
  { month: "May", visitors: 1890, pageviews: 4800 },
  { month: "Jun", visitors: 2390, pageviews: 5800 },
]

export default function AreaChartExample() {
  return (
    <AreaChart
      data={data}
      areas={[
        { dataKey: "visitors", name: "Visitors", fill: "var(--chart-1)" },
        { dataKey: "pageviews", name: "Pageviews", fill: "var(--chart-2)" },
      ]}
      xAxis={{ dataKey: "month" }}
      height={350}
    />
  )
}

Props

AreaChartDataPoint

PropTypeDefaultDescription

AreaChartArea

PropTypeDefaultDescription
dataKey*string-The data key to plot from your data points
namestring | undefined-Display name for the legend and tooltip
fillstring | undefined-Area fill color (use CSS custom property or hex)
strokestring | undefined-Area stroke color
strokeWidthnumber | undefined-Stroke thickness in pixels
fillOpacitynumber | undefined-Fill opacity (0-1)
stackIdstring | undefined-Stack ID for stacked areas (areas with same stackId will stack)
animationDurationnumber | undefined-Whether to animate the area on mount
type"basis" | "basisClosed" | "basisOpen" | "linear" | "linearClosed" | "natural" | "monotoneX" | "monotoneY" | "monotone" | "step" | "stepBefore" | "stepAfter" | undefined-Area type

AreaChartAxis

PropTypeDefaultDescription
dataKeystring | undefined-The data key for this axis
axisLineboolean | undefined-Whether to show the axis line
tickLineboolean | undefined-Whether to show tick marks
tickFormatter((value: unknown) => string) | undefined-Custom tick formatter function
labelstring | { value: string; angle?: number | undefined; position?: string | undefined; } | undefined-Label for the axis
hideboolean | undefined-Whether to hide the axis entirely
tickboolean | object | undefined-Axis tick styles

AreaChartGrid

PropTypeDefaultDescription
horizontalboolean | undefined-Show horizontal grid lines
verticalboolean | undefined-Show vertical grid lines
strokestring | undefined-Grid line stroke color
strokeDasharraystring | undefined-Grid line stroke dash pattern

AreaChartLegend

PropTypeDefaultDescription
verticalAlign"bottom" | "top" | "middle" | undefined-Legend position
align"left" | "center" | "right" | undefined-
layout"horizontal" | "vertical" | undefined-Legend layout
iconType"line" | "plainline" | "square" | "rect" | "circle" | "cross" | "diamond" | "star" | "triangle" | "wye" | undefined-Custom icon type
formatter((value: string) => ReactNode) | undefined-Custom legend formatter

AreaChartTooltip

PropTypeDefaultDescription
labelFormatter((label: unknown) => ReactNode) | undefined-Custom tooltip formatter for label
formatter((value: ValueType, name: NameType, item: unknown) => ReactNode) | undefined-Custom tooltip formatter for values
cursorboolean | object | undefined-Cursor style

AreaChartProps

PropTypeDefaultDescription
data*AreaChartDataPoint[]-Array of data points to plot
areas*AreaChartArea[]-Array of area configurations
widthnumber | undefined-Chart width in pixels
heightnumber | undefined-Chart height in pixels
xAxisAreaChartAxis | undefined-X-axis configuration
yAxisAreaChartAxis | undefined-Y-axis configuration
gridboolean | AreaChartGrid | undefined-Grid configuration
legendboolean | AreaChartLegend | undefined-Legend configuration (false to hide)
tooltipboolean | AreaChartTooltip | undefined-Tooltip configuration (false to hide)
margin{ top?: number | undefined; right?: number | undefined; bottom?: number | undefined; left?: number | undefined; } | undefined-Chart margin (top, right, bottom, left)
isLoadingboolean | undefined-Loading state
emptyStateReactNode-Empty state content
onDataPointClick((data: unknown, index: number) => void) | undefined-Click handler for area data points
responsiveboolean | undefined-Responsive container (auto-sizes to parent)
classNamestring | undefined-Container className
styleCSSProperties | undefined-Custom container styles

npm dependencies

recharts@^2.15.0

Changelog

Changelog - AreaChart

0.2.2

  • Fix onDataPointClick's index argument always being 0 regardless of which point was clicked. Now derived from Recharts' activeTooltipIndex via chart-core's resolveChartClickIndex.

0.2.1

  • Update data-testid call sites for the renamed prop.

0.2.0

  • Factor shared colors, tooltip/legend config, skeleton, and empty state into the chart-core widget; public API unchanged.

0.1.1

  • Replaced any types with proper Recharts types (ValueType, NameType) in AreaChartTooltip.formatter and AreaChartTooltip.labelFormatter.
  • Tightened tickFormatter, onDataPointClick signatures from any to unknown.

0.1.0

Initial release.

  • Area chart component with Recharts integration
  • Support for multiple areas with custom colors and styling
  • Stacked areas support via stackId
  • Multiple curve types (monotone, natural, step, linear, etc.)
  • Fill opacity control for transparency effects
  • Configurable axes, grid, legend, and tooltip
  • Responsive container support
  • Loading skeleton and empty state
  • Fully presentational (props-in/events-out pattern)