Charts guide

BarChart

Grouped vertical or horizontal SVG bars.

Install

npx shadcn@latest add @foldcn/bar-chart

BarChart parameters

ParameterType / propsBehavior
dataReadonlyArray<Datum> | undefinedRows used by series and axis dataKey accessors. Scatter can supply data on each series.
childrenCartesianChild[]Descriptors for series, axes, grid, tooltip, and legend.
defsHtml[]SVG definitions such as gradients referenced by a series fill.
width / heightnumberSVG dimensions. Defaults to 700 × 433.
responsivebooleanFits the SVG to the available width.
layouthorizontal | verticalChanges the category direction.
margin{ top?, right?, bottom?, left? }Plot margins in pixels.
barGap / barCategoryGapnumberBar spacing parameters; barGap applies to grouped bars.
stackOffsetsign | expandSeparates signed stacks or normalizes stacked area values to 100%.
activeLabelsbooleanShows the active row values beside each series point.
accessibilityLayerbooleanEnables keyboard focus and arrow, Home, End, and Escape navigation.
activeIndex / onActiveIndexChangenumber | null / callbackCaller-owned active tooltip state.
onLegendHover / onLegendClickcallbacksDispatches legend focus and click actions for interactive series.
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.
title / classNamestringAccessible SVG label and wrapper class.

Child components

ParameterType / propsBehavior
Area / Bar / ScatterdataKey, data, name, stroke, fill, type, stackId, yAxisId, hide, zDataKey, radius, cells, background, activeBar, shape, symbols, symbolColors, symbolSize, line, lineJointType, labelDataKey, label, labelFormatter, animationKind, animationDuration, animationKey, animationMatchBy, animationVariant, animationExitDatumRenders a numeric series. Area supports fillOpacity and connectNulls; Bar supports ranges, per-row cells, background tracks, activeBar, barSize, radius, and minPointSize; Scatter supports row data, Z sizing, symbols, labels, and joined lines. Matching stackIds stack Area or Bar series. Animation options cover the included source examples.
LinedataKey, name, stroke, type, dot, hide, legendTypeRenders a line series in ComposedChart; legendType none omits its legend entry.
ZAxisdataKey, rangeMaps scatter Z values to bubble area.
XAxis / YAxisdataKey, type, scale, domain, padding, hide, tick, tickCount, niceTicks, width, height, interval, tickAngle, tickFormatter, label, xAxisId, yAxisId, orientation, mirror, unitCategory and numeric axes.
CartesianGridhorizontal, vertical, stroke, strokeDasharrayPlot grid.
Tooltip / Legendformatter, labelFormatter / align, position, wrapperStyleDisplays active values and a series key.
ReferenceLinex, y, stroke, strokeDasharrayMarks a category or numeric value.
BrushdataKey, height, strokeDraws a range track below a Bar or Line chart.

Supports grouped, stacked, range, and custom-shaped bars, separate left and right numeric axes, secondary X-axis tick callbacks, scroll growth, and example streaming animations. Default transition timing remains 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