ComponentUpdated in v15

Bar Chart

Vertical bars for one series of values.

Installation

Import the class, and @use the entry point in your global styles: without it the component renders unstyled.

import { Component } from '@angular/core';
import { WrBarChart } from 'ngwr/charts/bar-chart';

@Component({ imports: [WrBarChart] })
export class MyComponent {}

Basic

<wr-bar-chart [data]="bars" />

Tooltip

Set [tooltip]="false" to turn it off.

<wr-bar-chart [data]="bars" />
<wr-bar-chart [data]="bars" [tooltip]="false" />

On (default)

[tooltip]="false"

API

NameDescriptionTypeDefault
dataThe bars, left to right. One series: a datum with no color of its own takes the chart's color, so by default every bar comes out the same.readonly WrBarChartDatum[][]
ariaLabelAccessible name of the CHART. Falls back to barChart.label, then 'Bar chart'. Every bar already carries its own role="img" and its own "Mon: 12", and that is what the plot had instead of a name of its own — so the chart announced as whatever its first bar said, and a page with three bar charts offered a reader three images called by a weekday. The four sibling charts all name the plot; this one was the omission.string | nullnull
colorDefault bar colour when a datum has none.stringprimary
showValuesShow value labels above each bar.booleantrue
heightPixel height of the chart area.number200
maxExplicit max value. 0 = auto.number0
tooltipShow a tooltip with the bar's label and value on hover. Pointer only — the column's accessible name already carries both.booleantrue
valueFormatWrites every number the chart shows: the labels above the bars, the tooltip and each bar's accessible name. null uses Intl.NumberFormat in LOCALE_ID, with compact labels from a thousand up (1.2K, 3.4M).((value: number) => string) | nullnull

Types

interface WrBarChartDatum {
  label: string;
  value: number;
  color?: string;
}
NameDescriptionTypeDefault
WrBarChartDatumOne bar of data.interface—
labelrequiredCategory label under the bar.string—
valuerequiredBar magnitude.number—
colorCSS colour for this bar. Unset, it takes the chart's color.stringthe chart’s `color`

CSS variables

Set these on the component's selector or a wrapper, not on :root: the defaults are declared on ngwr/charts/bar-chart's own element.

VariableDefaultDeclared on
--wr-bar-chart-bar-radiusvar(--wr-border-radius-sm).wr-bar-chart__bar
--wr-bar-chart-column-gapvar(--wr-space-xs).wr-bar-chart__column
--wr-bar-chart-font-familyvar(--wr-font-family-base).wr-bar-chart
--wr-bar-chart-label-font-sizevar(--wr-text-xs).wr-bar-chart__label
--wr-bar-chart-labels-gapvar(--wr-space-sm).wr-bar-chart__labels
--wr-bar-chart-labels-margin-topvar(--wr-space-sm).wr-bar-chart__labels
--wr-bar-chart-plot-bordervar(--wr-border-base).wr-bar-chart__plot
--wr-bar-chart-plot-gapvar(--wr-space-sm).wr-bar-chart__plot
--wr-bar-chart-value-font-sizevar(--wr-text-xs).wr-bar-chart__value
--wr-bar-chart-value-line-heightvar(--wr-leading-none).wr-bar-chart__value

Dependencies

Built onPopover

See also