Charts guide
LineChart
SVG line chart with Recharts-shaped descriptors and caller-owned hover state.
Install
npx shadcn@latest add @foldcn/line-chartLineChart parameters
| Parameter | Type / props | Behavior |
|---|---|---|
data | ReadonlyArray<Datum> | Rows of data. Lines and axes select values with dataKey. |
children | ChartChild[] | Descriptors returned by Line, XAxis, YAxis, CartesianGrid, Tooltip, Legend, and ReferenceLine. |
width / height | number | SVG dimensions. Defaults to 700 × 433. |
responsive | boolean | Makes the SVG fit the available width while preserving its aspect ratio. |
layout | horizontal | vertical | Sets category direction. Defaults to horizontal. |
margin | { top?, right?, bottom?, left? } | Space around the plot in pixels. |
activeIndex | number | null | Controlled index shown by Tooltip. |
onActiveIndexChange | (index: number | null) => Message | Dispatches hover changes into the Foldkit update loop. |
onLegendHover | (key: string | null) => Message | Dispatches legend hover changes for interactive line styling. |
selection | { fromIndex, toIndex } | Draws a drag selection over the plot. |
onSelectionStart / onSelectionEnd | (index: number) => Message | Dispatches drag endpoints so the caller can set a zoomed domain. |
brushRange / brushDataLength | [start, end] / number | Shows a controlled Brush window against the full data length. |
onBrushStart / onBrushEnd | callbacks | Dispatches Brush handle dragging so the caller can update its visible data window. |
accessibilityLayer | boolean | Enables a focusable SVG with arrow, Home, End, and Escape navigation. |
title / className | string | Accessible chart label and wrapper class. |
Child components
| Parameter | Type / props | Behavior |
|---|---|---|
Line | dataKey, yAxisId, name, type, stroke, strokeWidth, strokeDasharray, strokeOpacity, zIndex, dot, label, connectNulls, hide, animationDuration, animationKind, animationKey | Draws a data series. type supports linear, monotone, step, basis, cardinal, and natural curves. dot accepts a callback for custom SVG markers. animationKind supports opacity and swipe-left. |
XAxis / YAxis | dataKey, yAxisId, orientation, type, scale, domain, padding, width, height, interval, tick, tickCount, tickAngle, stroke, tickFormatter, label | Category labels and numeric ticks. domain accepts numbers, auto, dataMin, and dataMax. |
CartesianGrid | horizontal, vertical, stroke, strokeDasharray | Draws plot grid lines. |
Tooltip | formatter, labelFormatter, defaultIndex | Shows values for the controlled or initial active index. |
Legend | align, position, itemSorter, wrapperStyle | Lists visible series with their stroke colors. |
Brush | dataKey, height, stroke | Draws a range track below the plot. |
ReferenceLine | x, y, stroke, strokeDasharray | Marks a category or numeric value. |
Supports lines, left and right numeric axes, grid, reference lines, legend, controlled tooltip, drag selection for zoom, controlled brush ranges, custom dots, and example animation modes. Some Recharts animation transitions remain approximate.
Examples
The first example is open. Expand Source inside an example to view its code. Other examples load when opened.