Skip to Content

Bar Chart

A bar chart uses rectangular bars to show values, with one axis for categories and the other for values. It’s great for visualizing data like months, age groups, or product types. Bar charts help compare different categories and track trends over time. With REAVIZ, you can easily create and customize bar charts to suit your data visualization needs!

Types supported by reaviz:

Where to use:

  • Compare Quantities: Compare different categories, like sales figures.
  • Highlight Largest/Smallest Categories: Identify categories with highest or lowest values.
  • Visualize Categorical Data: Display distinct categories, such as age groups or product types.

Quick Start

To create a Bar chart, use import the BarChart and give it data. The chart will automatically configure itself with the default options exposed via props.

Examples

Single Series Vertical

Single Series Horizontal

Multi Series Vertical

Multi Series Horizontal

Target Markers Vertical

Target Markers Horizontal

Stacked Vertical

Stacked Horizontal

Stacked Normalized Vertical

Stacked Normalized Horizontal

Stacked Diverging Vertical

Stacked Diverging Horizontal

Marimekko

Sparkline

Waterfall

Histograms

Customization

Customize the Bar Chart using various props:

  • colorScheme: Array of colors for the chart.
  • gridlines: Toggle gridlines on or off.
  • bar: Customize the appearance of the bars.
  • legend and tooltips: Add legends and tooltips for better data interpretation.

API

BarChartΒ 

NameTypeDefault
dataChartDataShape[]

Data the chart will receive to render.

[]
seriesReactElement<BarSeriesProps, FC<Partial<BarSeriesProps>>>

The series component that renders the bar components.

`<BarSeries />`
yAxisReactElement<LinearAxisProps, FC<Partial<LinearAxisProps>>>

The linear axis component for the Y Axis of the chart.

`<LinearYAxis type="value" />`
xAxisReactElement<LinearAxisProps, FC<Partial<LinearAxisProps>>>

The linear axis component for the X Axis of the chart.

`<LinearXAxis type="category" tickSeries={<LinearXAxisTickSeries tickSize={20} />} />`
gridlinesReactElement<GridlineSeriesProps, FC<Partial<GridlineSeriesProps>>> | null

The chart’s background gridlines component.

`<GridlineSeries />`
brushReactElement<ChartBrushProps, FC<Partial<ChartBrushProps>>> | null

The chart’s brush component.

secondaryAxisReactElement<LinearAxisProps, FC<Partial<LinearAxisProps>>>[]

Any secondary axis components. Useful for multi-axis charts.

idstring

Id of the chart.

widthnumber

Width of the chart. If not provided will autosize.

heightnumber

Height of the chart. If not provided will autosize.

marginsMargins

Margins for the chart.

classNamestring

Classnames for the chart.

containerClassNamestring

Classnames for the chart.

styleStyleHTMLAttributes<SVGSVGElement>

Additional css styles.

centerboolean

Center the chart. Used mainly internally.

centerXboolean

Center chart on X Axis only. Used mainly internally.

centerYboolean

Center chart on Y Axis only. Used mainly internally.

BarSeriesΒ 

NameTypeDefault
dataChartInternalDataShape[]

Parsed data shape. Set internally by BarChart.

idstring

Id of the bar chart. Set internally by BarChart.

xScaleany

D3 scale for X Axis. Set internally by BarChart.

yScaleany

D3 scale for Y Axis. Set internally by BarChart.

xScale1any

D3 scale for X Multi-Group Axis. Set internally by BarChart.

barBarElement | BarElement[]

Bar element.

`<Bar />`
typeBarType

Type of the chart.

'standard'
colorSchemeColorSchemeType

Color scheme for the chart.

'cybertron'
animatedboolean

Whether the chart is animated or not.

true
paddingnumber

Amount of padding between each bar.

0.1
groupPaddingnumber

Amount of padding between each group.

16
isCategoricalboolean

Whether the chart is categorical or not. Set internally by BarChart.

layoutDirection

Direction of the chart

'vertical'
binSizenumber

The size of each bin/bucket in the bar chart.

heightnumber

Height of the chart. Set internally by BarChart.

widthnumber

Width of the chart. Set internally by BarChart.

tooltipReactElement<TooltipAreaProps, ForwardRefExoticComponent<Partial<TooltipAreaProps> & RefAttributes<any>>> | null

Tooltip for the chart area.

`<TooltipArea tooltip={<ChartTooltip followCursor modifiers={[offset(5)]} />} />`
valueMarkersReactElement<LinearValueMarkerProps, FC<LinearValueMarkerProps>>[] | null

Value markers line for the chart.

BarΒ 

NameTypeDefault
activeboolean

Whether the bar is active or not.

activeBrightnessnumber

Chroma brightness factor to brighten the active bar. See https://gka.github.io/chroma.js/#color-brightenΒ  for more info.

0.5
xScaleany

D3 scale for X Axis. Set internally by BarChart.

yScaleany

D3 scale for Y Axis. Set internally by BarChart.

xScale1any

D3 scale for X Multi-Group Axis. Set internally by BarChart.

dataChartInternalShallowDataShape

Parsed data shape. Set internally by BarChart.

idstring

Id set internally by BarChart.

gradientReactElement<GradientProps, FC<Partial<GradientProps>>> | null

Gradient shades for the bar.

`<Gradient />`
rxnumber

SVG rx attribute for the bar.

0
rynumber

SVG ry attribute for the bar.

0
widthnumber

Width of the bar. Set internally by BarSeries.

paddingnumber

Padding for the bar groups.

barCountnumber

Total number of bars used for animation. Set internally by BarSeries.

colorany

Color callback for the bar.

cursorstring

Cursor for the bar element.

'auto'
barIndexnumber

Index of the bar. Set internally by BarSeries.

groupIndexnumber

Index of the group. Set internally by BarSeries.

animatedboolean

Whether to animate the enter/update/exit. Set internally by BarSeries.

isCategoricalboolean

Whether this is categorical chart or not. Set internally by BarSeries.

rangeLinesReactElement<RangeLinesProps, FC<Partial<RangeLinesProps>>> | null

Rangelines element. for the bar.

maskReactElement<MaskProps, FC<MaskProps>> | null

Mask element for the bar.

tooltipReactElement<ChartTooltipProps, FC<Partial<ChartTooltipProps>>> | null

Tooltip element.

layoutDirection

Direction of the chart. Set internally by BarSeries.

'vertical'
typeBarType

Type of bar chart. Set internally by BarSeries.

labelReactElement<BarLabelProps, FC<Partial<BarLabelProps>>> | null

Label element.

targetMarkerReactElement<BarTargetMarkerProps, FC<Partial<BarTargetMarkerProps>>> | null

Target marker element.

`<BarTargetMarker />`
guideReactElement<GuideBarProps, FC<Partial<GuideBarProps>>> | null

Guide bar component.

minHeightnumber

Force a min height on the bar.

glowGlow

Glow styling for the bar.

onClick(event: ClickEvent) => void

Event for when the bar is clicked.

onMouseEnter(event: any) => void

Event for when the bar has mouse enter.

onMouseLeave(event: any) => void

Event for when the bar has mouse leave.

onMouseMove(event: any) => void

Event for when a bar has mouse move.

classNameany

Classnames to apply to the element.

styleany

CSS styles to apply to the element.

GuideBarΒ 

NameTypeDefault
activeboolean

Whether the guide bar is active.

fillstring

Fill for the guide bar element.

'#eee'
opacitynumber

Opacity for the guide bar element.

0.15

RangeLinesΒ 

NameTypeDefault
heightnumber

Height of the bar.

widthnumber

Width of the bar.

xnumber

SVG x attribute for the bar.

ynumber

SVG y attribute for the bar.

indexnumber

Group index or index of the bar. Set internally by BarSeries.

strokeWidthnumber

Stroke width of the range line.

1
scaleany

D3 scale for Axis. Set internally by BarChart.

position"top" | "bottom"

Position of the range line.

'top'
dataChartInternalShallowDataShape

Parsed data shape. Set internally by BarChart.

colorstring

Color for the range line.

barCountnumber

Total number of bars used for animation. Set internally by BarSeries.

layoutDirection

Direction of the chart. Set internally by BarSeries.

'vertical'
animatedboolean

Whether to animate the enter/update/exit. Set internally by BarSeries.

typeBarType

Type of bar chart. Set internally by BarSeries.

BarLabelΒ 

NameTypeDefault
textstring

Text of the label. Set internally by Bar.

heightnumber

Height of the bar.

widthnumber

Width of the bar.

xnumber

SVG x attribute for the bar.

ynumber

SVG y attribute for the bar.

indexnumber

Group index or index of the bar. Set internally by BarSeries.

scaleany

D3 scale for Axis. Set internally by BarChart.

position"top" | "center" | "bottom"

Position of the label.

'top'
dataChartInternalShallowDataShape

Parsed data shape. Set internally by BarChart.

fillstring

Color of the text.

'#000'
barCountnumber

Number of the bars in the bar group. Set internally by BarSeries.

layoutDirection

Layout of bar chart to render. Set internally by BarSeries.

'vertical'
animatedboolean

Whether to animate the enter/update/exit. Set internally by BarSeries.

typeBarType

Type of bar chart to render. Set internally by BarSeries.

fontSizenumber

Font size of the text.

13
fontFamilystring

Font family of the text.

'sans-serif'
paddingnumber

Padding of the label.

5
classNameany

Class name to apply to the text.

Last updated on