Bar Chart

Bar charts compare quantities across categories using rectangular bars. They work well for showing rankings, highlighting differences between groups, and tracking changes across time periods.

For advanced configuration such as mixed chart types, custom plugins, and direct Chart.js access, see <wa-chart>.

Examples

Link to This Section

Providing Data with JavaScript

Link to This Section

For dynamic data, set the config property directly. The chart will re-render automatically.

Note that config is shallowly reactive. If you mutate the existing object in place, you must reassign it to trigger a re-render!

Providing Data with JSON

Link to This Section

Place a <script type="application/json"> tag inside the component with your chart data. The type field can be omitted since wa-bar-chart already knows its chart type.

Multiple Datasets

Link to This Section

Add multiple objects to the datasets array to compare groups side by side.

Custom Colors

Link to This Section

Override the default color palette using the --fill-color-* and --border-color-* CSS custom properties on the component.

Horizontal Bars

Link to This Section

Use the orientation="horizontal" attribute to render bars horizontally. This is useful when category labels are long or when you want to emphasize ranking.

Stacked Bars

Link to This Section

Use the stacked attribute to stack datasets on top of each other. This is helpful for showing how parts contribute to a total.

Border Width

Link to This Section

Use the --border-width CSS custom property to control the thickness of bar borders.

Legend

Link to This Section

Use the legend-position attribute to control where the legend appears. Supported values include top (default), bottom, left, right, start, and end. The start and end values are direction-aware and will flip in RTL layouts. Add without-legend to hide it entirely.

Grid Lines

Link to This Section

Use the grid attribute to control which axes show grid lines. Options are both (default), x, y, and none.

Axis Labels

Link to This Section

Use the x-label and y-label attributes to add descriptive labels to each axis.

Axis Range

Link to This Section

Use the min and max attributes to constrain the value axis.

Disabling Tooltips

Link to This Section

Use the without-tooltip attribute to hide the tooltips that appear when hovering over data points.

Disabling Animations

Link to This Section

Use the without-animation attribute to disable chart transitions.

Importing

Link to This Section

If you're using the autoloader or a hosted project, components load on demand — no manual import needed. To cherry-pick a component manually, use one of the following snippets.

CDN npm Self-Hosted React

Import this component directly from the CDN:

import 'https://ka-f.webawesome.com/[email protected]/components/bar-chart/bar-chart.js';

After installing Web Awesome via npm, import this component:

import '@awesome.me/webawesome/dist/components/bar-chart/bar-chart.js';

If you're self-hosting Web Awesome, import this component from your server:

import './webawesome/dist/components/bar-chart/bar-chart.js';

To import this component for React 18 or below, use the following code:

import WaBarChart from '@awesome.me/webawesome/dist/react/bar-chart/index.js';

Slots

Link to This Section

Learn more about using slots.

Attributes & Properties

Link to This Section

Learn more about attributes and properties.

CSS custom properties

Link to This Section

Learn more about CSS custom properties.

Need a hand? Report a bug Ask for help