Skip to main content
BarChart
@coinbase/cds-web@9.28.0
A bar chart component for comparing values across categories. Supports horizontal and vertical orientations, stacked bars, and grouped series.
import { BarChart } from '@coinbase/cds-web/visualizations/chart'
Peer dependencies
  • framer-motion: ^10.18.0
Related components

BarChart is a wrapper for CartesianChart for comparing discrete categories, with a default value-axis minimum that follows the baseline (0 when baseline is not set).

Basics​

Bar charts are a useful component for comparing discrete categories of data. They are helpful for highlighting trends to users or allowing them to compare proportions at a glance.

To start, pass in a series of data to the chart.

Loading...

Layout​

You can set layout to horizontal to render the chart horizontally.

Loading...

Multiple Series​

You can also provide multiple series of data to the chart. Series will have their bars for each data point rendered side by side.

Loading...

Series Stacking​

You can also configure stacking for your chart using the stacked prop.

Loading...

You can also configure multiple stacks by setting the stackId prop on each series.

Loading...

Stack Gap​

Loading...

Border Radius​

Bars have a default borderRadius of 4. You can change this by setting the borderRadius prop on the chart.

Stacks will only round the top corners of touching bars.

Loading...

Round Baseline​

You can also round the baseline of the bars by setting the roundBaseline prop on the chart.

Loading...

Data​

Negative​

Loading...

Null​

You can pass in null or 0 values to not render a bar for that data point.

Loading...

You can also use the BarStackComponent prop to render an empty circle for zero values.

Loading...

Range​

You can pass in [min, max] tuples as data points to render bars that span a range of values.

Loading...

Customization​

Bar Spacing​

There are two ways to control the spacing between bars. You can set the barPadding prop to control the spacing between bars within a series. You can also set the categoryPadding prop to control the spacing between stacks of bars.

Loading...

Minimum Size​

To better emphasize small values, you can set the stackMinSize or barMinSize prop to control the minimum size for entire stacks or individual bar.

Minimum Stack Size​

You can set the stackMinSize prop to control the minimum size for entire stacks. This will only apply to stacks that have a value that is not null or 0. It will proportionally scale the values of each bar in the stack to reach the minimum size.

Loading...

Minimum Bar Size​

You can also set the barMinSize prop to control the minimum size for individual bars. This will only apply to bars that have a value that is not null or 0.

Loading...

Multiple Axes​

You can render bars from separate y axes in one BarPlot, however they aren't able to be stacked.

Loading...

When using horizontal layout, you can use multiple x axes.

Loading...

Custom Components​

Outlined Stacks​

You can set the BarStackComponent prop to render a custom component for stacks.

Loading...

Animations​

You can configure chart transitions using the transitions prop. Also, you can toggle animations by setting animate to true or false.

Loading...

Composed Examples​

Candlesticks​

You can render a candlestick chart by setting the BarComponent prop to a custom candlestick component.

Loading...

Monthly Sunlight​

You can combine custom and BarPlot components and transitions to create a springy sunlight chart.

Loading...

Buy vs Sell​

You can combine a horizontal BarChart with a custom legend to create a buy vs sell chart.

Loading...

Is this page useful?

Coinbase Design is an open-source, adaptable system of guidelines, components, and tools that aid the best practices of user interface design for crypto products.