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:
- Single Series Vertical / Horizontal
- Multi Series Vertical / Horizontal
- Stacked Vertical / Horizontal
- Stacked Normalized Vertical / Horizontal
- Stacked Diverging Vertical / Horizontal
- Marimekko
- Sparkline
- Waterfall
- Histograms
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
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 (opens in a new tab)
Prop | Description | Default |
---|---|---|
data | Data the chart will receive to render.ChartDataShape[] | [] |
series | The series component that renders the bar components.ReactElement<BarSeriesProps, FC<Partial<BarSeriesProps>>> | <BarSeries /> |
yAxis | The linear axis component for the Y Axis of the chart.ReactElement<LinearAxisProps, FC<Partial<LinearAxisProps>>> | <LinearYAxis type="value" /> |
xAxis | The linear axis component for the X Axis of the chart.ReactElement<LinearAxisProps, FC<Partial<LinearAxisProps>>> | (
<LinearXAxis
type="category"
tickSeries={<LinearXAxisTickSeries tickSize={20} />}
/>
) |
gridlines | The chart's background gridlines component.ReactElement<GridlineSeriesProps, FC<Partial<GridlineSeriesProps>>> | <GridlineSeries /> |
brush | The chart's brush component.ReactElement<ChartBrushProps, FC<Partial<ChartBrushProps>>> | null |
secondaryAxis | Any secondary axis components. Useful for multi-axis charts.ReactElement<LinearAxisProps, FC<Partial<LinearAxisProps>>>[] | |
id | Id of the chart.string | |
width | Width of the chart. If not provided will autosize.number | |
height | Height of the chart. If not provided will autosize.number | |
margins | Margins for the chart.Margins | |
className | Classnames for the chart.string | |
containerClassName | Classnames for the chart.string | |
style | Additional css styles.StyleHTMLAttributes<SVGSVGElement> | |
center | Center the chart. Used mainly internally.boolean | |
centerX | Center chart on X Axis only. Used mainly internally.boolean | |
centerY | Center chart on Y Axis only. Used mainly internally.boolean |
BarSeries (opens in a new tab)
Prop | Description | Default |
---|---|---|
data | Parsed data shape. Set internally by `BarChart`.ChartInternalDataShape[] | |
id | Id of the bar chart. Set internally by `BarChart`.string | |
xScale | D3 scale for X Axis. Set internally by `BarChart`.any | |
yScale | D3 scale for Y Axis. Set internally by `BarChart`.any | |
xScale1 | D3 scale for X Multi-Group Axis. Set internally by `BarChart`.any | |
bar | Bar element.BarElement | BarElement[] | <Bar /> |
type | Type of the chart.BarType | standard |
colorScheme | Color scheme for the chart.ColorSchemeType | cybertron |
animated | Whether the chart is animated or not.boolean | true |
padding | Amount of padding between each bar.number | 0.1 |
groupPadding | Amount of padding between each group.number | 16 |
isCategorical | Whether the chart is categorical or not. Set internally by `BarChart`.boolean | |
layout | Direction of the chartDirection | vertical |
binSize | The size of each bin/bucket in the bar chart.number | |
height | Height of the chart. Set internally by `BarChart`.number | |
width | Width of the chart. Set internally by `BarChart`.number | |
tooltip | Tooltip for the chart area.ReactElement<TooltipAreaProps, ForwardRefExoticComponent<Partial<TooltipAreaProps> & RefAttributes<any>>> | (
<TooltipArea
tooltip={<ChartTooltip followCursor={true} modifiers={[offset(5)]} />}
/>
) |
valueMarkers | Value markers line for the chart.ReactElement<LinearValueMarkerProps, FC<LinearValueMarkerProps>>[] |
Bar (opens in a new tab)
Prop | Description | Default |
---|---|---|
active | Whether the bar is active or not.boolean | |
activeBrightness | Chroma brightness factor to brighten the active bar. See
https://gka.github.io/chroma.js/#color-brighten for more info.number | 0.5 |
xScale | D3 scale for X Axis. Set internally by `BarChart`.any | |
yScale | D3 scale for Y Axis. Set internally by `BarChart`.any | |
xScale1 | D3 scale for X Multi-Group Axis. Set internally by `BarChart`.any | |
data | Parsed data shape. Set internally by `BarChart`.ChartInternalShallowDataShape | |
id | Id set internally by `BarChart`.string | |
gradient | Gradient shades for the bar.ReactElement<GradientProps, FC<Partial<GradientProps>>> | <Gradient /> |
rx | SVG rx attribute for the bar.number | 0 |
ry | SVG ry attribute for the bar.number | 0 |
width | Width of the bar. Set internally by `BarSeries`.number | |
padding | Padding for the bar groups.number | |
barCount | Total number of bars used for animation. Set internally by `BarSeries`.number | |
color | Color callback for the bar.any | |
cursor | Cursor for the bar element.string | auto |
barIndex | Index of the bar. Set internally by `BarSeries`.number | |
groupIndex | Index of the group. Set internally by `BarSeries`.number | |
animated | Whether to animate the enter/update/exit. Set internally by `BarSeries`.boolean | |
isCategorical | Whether this is categorical chart or not. Set internally by `BarSeries`.boolean | |
rangeLines | Rangelines element. for the bar.ReactElement<RangeLinesProps, FC<Partial<RangeLinesProps>>> | null |
mask | Mask element for the bar.ReactElement<MaskProps, FC<MaskProps>> | |
tooltip | Tooltip element.ReactElement<ChartTooltipProps, FC<Partial<ChartTooltipProps>>> | null |
layout | Direction of the chart. Set internally by `BarSeries`.Direction | vertical |
type | Type of bar chart. Set internally by `BarSeries`.BarType | |
label | Label element.ReactElement<BarLabelProps, FC<Partial<BarLabelProps>>> | null |
guide | Guide bar component.ReactElement<GuideBarProps, FC<Partial<GuideBarProps>>> | null |
minHeight | Force a min height on the bar.number | |
glow | Glow styling for the bar.Glow | |
onClick | Event for when the bar is clicked.(event: ClickEvent) => void | |
onMouseEnter | Event for when the bar has mouse enter.(event: any) => void | |
onMouseLeave | Event for when the bar has mouse leave.(event: any) => void | |
onMouseMove | Event for when a bar has mouse move.(event: any) => void | |
className | Classnames to apply to the element.any | |
style | CSS styles to apply to the element.any |
GuideBar (opens in a new tab)
Prop | Description | Default |
---|---|---|
active | Whether the guide bar is active.boolean | |
fill | Fill for the guide bar element.string | #eee |
opacity | Opacity for the guide bar element.number | 0.15 |
height | number | |
width | number | |
x | number | |
y | number | |
bottom | number | |
left | number | |
right | number | |
top | number | |
toJSON | () => any |
RangeLines (opens in a new tab)
Prop | Description | Default |
---|---|---|
height | Height of the bar.number | |
width | Width of the bar.number | |
x | SVG x attribute for the bar.number | |
y | SVG y attribute for the bar.number | |
index | Group index or index of the bar. Set internally by `BarSeries`.number | |
strokeWidth | Stroke width of the range line.number | 1 |
scale | D3 scale for Axis. Set internally by `BarChart`.any | |
position | Position of the range line."top" | "bottom" | top |
data | Parsed data shape. Set internally by `BarChart`.ChartInternalShallowDataShape | |
color | Color for the range line.string | |
barCount | Total number of bars used for animation. Set internally by `BarSeries`.number | |
layout | Direction of the chart. Set internally by `BarSeries`.Direction | vertical |
animated | Whether to animate the enter/update/exit. Set internally by `BarSeries`.boolean | |
type | Type of bar chart. Set internally by `BarSeries`.BarType |
BarLabel (opens in a new tab)
Prop | Description | Default |
---|---|---|
text | Text of the label. Set internally by `Bar`.string | |
height | Height of the bar.number | |
width | Width of the bar.number | |
x | SVG x attribute for the bar.number | |
y | SVG y attribute for the bar.number | |
index | Group index or index of the bar. Set internally by `BarSeries`.number | |
scale | D3 scale for Axis. Set internally by `BarChart`.any | |
position | Position of the label."top" | "center" | "bottom" | top |
data | Parsed data shape. Set internally by `BarChart`.ChartInternalShallowDataShape | |
fill | Color of the text.string | #000 |
barCount | Number of the bars in the bar group. Set internally by `BarSeries`.number | |
layout | Layout of bar chart to render. Set internally by `BarSeries`.Direction | vertical |
animated | Whether to animate the enter/update/exit. Set internally by `BarSeries`.boolean | |
type | Type of bar chart to render. Set internally by `BarSeries`.BarType | |
fontSize | Font size of the text.number | 13 |
fontFamily | Font family of the text.string | sans-serif |
padding | Padding of the label.number | 5 |
className | Class name to apply to the text.any |