Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/recharts/recharts/llms.txt

Use this file to discover all available pages before exploring further.

Renders a group of rectangles in a Cartesian chart.

Usage

import { BarChart, Bar, XAxis, YAxis } from 'recharts';

<BarChart data={data} width={600} height={300}>
  <XAxis dataKey="name" />
  <YAxis />
  <Bar dataKey="value" fill="#8884d8" />
</BarChart>

Props

dataKey
string | number | function
required
The key or getter function of a group of data which should be displayed in the bar.
fill
string
The fill color of bars.
stroke
string
The stroke color of bars.
strokeWidth
string | number
The width of the stroke.
barSize
string | number
The width or height of each bar. If the barSize is not specified, the size of bar will be calculated by the barCategoryGap, barGap and the quantity of bar groups.
maxBarSize
number
The maximum width of bar in a horizontal chart, or maximum height in a vertical chart.
minPointSize
number | function
default:"0"
The minimal height of a bar in a horizontal chart, or the minimal width of a bar in a vertical chart.By default, 0 values are not shown. To visualize a 0 (or close to zero) point, set the minimal point size to a pixel value like 3.In stacked bar charts, minPointSize might not be respected for tightly packed values. So we strongly recommend not using this props in stacked BarChart.You may provide a function to conditionally change this prop based on Bar value.
stackId
string | number
When two Bars have the same axisId and same stackId, then the two Bars are stacked in the chart.
radius
number | [number, number, number, number]
The radius of corners.If you provide a single number, it applies to all four corners. If you provide an array of four numbers, they apply to top-left, top-right, bottom-right, bottom-left corners respectively.
shape
ReactElement | function
If set a ReactElement, the shape of bar can be customized. If set a function, the function will be called to render customized shape. By default, renders a rectangle.
activeBar
boolean | object | ReactElement | function
default:"false"
The active bar is shown when a user enters a bar chart and this chart has tooltip. Options:
  • false: all bars are passive, nothing happens on mouse events
  • true: active bar is rendered separately but the default props are the same as others
  • object: the props of active bar
  • ReactElement: the active bar element
  • function: a render function of active bar
background
boolean | object | ReactElement | function
default:"false"
Renders a background for each bar. Options:
  • false: no background
  • true: renders default background
  • object: the props of background rectangle
  • ReactElement: a custom background element
  • function: a render function of custom background
label
boolean | object | ReactElement | function
default:"false"
Renders one label for each bar. Options:
  • true: renders default labels
  • false: no labels are rendered
  • object: the props of LabelList component
  • ReactElement: a custom label element
  • function: a render function of custom label
hide
boolean
default:"false"
Hides the whole graphical element when true.Hiding an element is different from removing it from the chart: Hidden graphical elements are still visible in Legend, and can be included in axis domain calculations, depending on includeHidden props of your XAxis/YAxis.
name
string | number
The name of data. This option will be used in tooltip and legend to represent a bar. If no value was set to this option, the value of dataKey will be used alternatively.
unit
string | number
The unit of data. This option will be used in tooltip.
xAxisId
string | number
default:"0"
The id of XAxis which is corresponding to the data. Required when there are multiple XAxes.
yAxisId
string | number
default:"0"
The id of YAxis which is corresponding to the data. Required when there are multiple YAxes.
legendType
LegendType
default:"rect"
The type of icon in legend. If set to ‘none’, no legend item will be rendered.
tooltipType
TooltipType
The type of tooltip item.

Animation props

isAnimationActive
boolean | 'auto'
default:"auto"
If set false, animation of bar will be disabled. If set “auto”, the animation will be disabled in SSR and will respect the user’s prefers-reduced-motion system preference for accessibility.
animationBegin
number
default:"0"
Specifies when the animation should begin, the unit of this option is ms.
animationDuration
number
default:"400"
Specifies the duration of animation, the unit of this option is ms.
animationEasing
EasingInput
default:"ease"
The type of easing function.
onAnimationStart
function
The customized event handler of animation start.
onAnimationEnd
function
The customized event handler of animation end.

Event handlers

onClick
function
The customized event handler of click on the bars in this group.
(data: BarRectangleItem, index: number, event: React.MouseEvent) => void
onMouseEnter
function
The customized event handler of mouseenter on the bars in this group.
onMouseLeave
function
The customized event handler of mouseleave on the bars in this group.
onMouseMove
function
The customized event handler of mousemove on the bars in this group.
onMouseDown
function
The customized event handler of mousedown on the bars in this group.
onMouseUp
function
The customized event handler of mouseup on the bars in this group.
onMouseOver
function
The customized event handler of mouseover on the bars in this group.
onMouseOut
function
The customized event handler of mouseout on the bars in this group.

Layout props

id
string
The unique identifier of this component. Used as an HTML attribute id, and also to identify this element internally.If undefined, Recharts will generate a unique ID automatically.
zIndex
number
default:"300"
Z-Index of this component and its children. The higher the value, the more on top it will be rendered. Components with higher zIndex will appear in front of components with lower zIndex. If undefined or 0, the content is rendered in the default layer without portals.@since 3.4
className
string
CSS class name for styling.

Source

https://github.com/recharts/recharts/blob/main/src/cartesian/Bar.tsx