Charts guide

LineChart

SVG line chart with Recharts-shaped descriptors and caller-owned hover state.

Install

npx shadcn@latest add @foldcn/line-chart

LineChart parameters

ParameterType / propsBehavior
dataReadonlyArray<Datum>Rows of data. Lines and axes select values with dataKey.
childrenChartChild[]Descriptors returned by Line, XAxis, YAxis, CartesianGrid, Tooltip, Legend, and ReferenceLine.
width / heightnumberSVG dimensions. Defaults to 700 × 433.
responsivebooleanMakes the SVG fit the available width while preserving its aspect ratio.
layouthorizontal | verticalSets category direction. Defaults to horizontal.
margin{ top?, right?, bottom?, left? }Space around the plot in pixels.
activeIndexnumber | nullControlled index shown by Tooltip.
onActiveIndexChange(index: number | null) => MessageDispatches hover changes into the Foldkit update loop.
onLegendHover(key: string | null) => MessageDispatches legend hover changes for interactive line styling.
selection{ fromIndex, toIndex }Draws a drag selection over the plot.
onSelectionStart / onSelectionEnd(index: number) => MessageDispatches drag endpoints so the caller can set a zoomed domain.
brushRange / brushDataLength[start, end] / numberShows a controlled Brush window against the full data length.
onBrushStart / onBrushEndcallbacksDispatches Brush handle dragging so the caller can update its visible data window.
accessibilityLayerbooleanEnables a focusable SVG with arrow, Home, End, and Escape navigation.
title / classNamestringAccessible chart label and wrapper class.

Child components

ParameterType / propsBehavior
LinedataKey, yAxisId, name, type, stroke, strokeWidth, strokeDasharray, strokeOpacity, zIndex, dot, label, connectNulls, hide, animationDuration, animationKind, animationKeyDraws 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 / YAxisdataKey, yAxisId, orientation, type, scale, domain, padding, width, height, interval, tick, tickCount, tickAngle, stroke, tickFormatter, labelCategory labels and numeric ticks. domain accepts numbers, auto, dataMin, and dataMax.
CartesianGridhorizontal, vertical, stroke, strokeDasharrayDraws plot grid lines.
Tooltipformatter, labelFormatter, defaultIndexShows values for the controlled or initial active index.
Legendalign, position, itemSorter, wrapperStyleLists visible series with their stroke colors.
BrushdataKey, height, strokeDraws a range track below the plot.
ReferenceLinex, y, stroke, strokeDasharrayMarks 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.

Iter: 0Iter: 1Iter: 2Iter: 3Iter: 4Iter: 50200400600800
xy
View the Recharts example