Skip to main content

BarChart

BasicCharts<co-bar-chart>

BarChart shows values per category or day with optional threshold line and out-of-range colours, for dashboards and remote monitoring.

import { BarChart } from 'health-components';

Examples​

Showcase​

Storybook

Plain​

Storybook

Tall​

Storybook

Usage​

<BarChart title="Systolic BP (mmHg)" data={readings.map(r => ({ label: r.day, value: r.sys, tone: r.sys >= 140 ? "hi" : "ok" }))} threshold={140} />

When to use​

  • Counts per day or per payer; readings against a target.

When not to use​

  • More than about 14 bars: a table or line chart.

Variants and states​

VariantWhat it is
defaultprimary bars.
toneshi (danger), lo (warning), ok (success), ai, accent.
thresholdDashed goal line with label.
legendExplains the tones.

Accessibility​

  • role img with every label and value in the aria-label; values are printed above bars.
  • Out-of-range bars also cross the threshold line, so colour is not the only cue.

Do and don't​

  • Do: Systolic BP per day with the 140 line.
  • Don't: 3D or gradient bars.

Props​

PropTypeDefaultDescription
data *BarChartDatum[]—Array<{label, value, tone?}>
titlestringnoneCaption above the chart and start of the accessible summary
heightnumber150Plot height in px
maxnumberauto (largest value)Top of the scale
thresholdnumbernoneValue of the dashed goal or limit line
thresholdLabelstring"Goal N"Label of the threshold line
unitstring""Unit appended to values in the accessible text, e.g. " mmHg"
legendBarChartLegendItem[]noneArray<{label, tone}>

Also accepts native attributes, including defaultChecked, defaultValue, autoFocus, plus className and event handlers on the root element.

Angular, Vue and HTML​

Register the elements once (Angular guide), then use <co-bar-chart>. Attributes take strings; arrays and objects are set as properties (Angular [prop], Vue :prop) or as JSON attributes. Callbacks are DOM events with the value in event.detail.

Angular template
<co-bar-chart title="…" height="…" [data]="data"></co-bar-chart>
KindNameDescription
property / JSON attributedataArray<{label, value, tone?}>
attributetitleCaption above the chart and start of the accessible summary; default none
attributeheightPlot height in px; default 150
attributemaxTop of the scale; default auto (largest value)
attributethresholdValue of the dashed goal or limit line; default none
attributethreshold-label / thresholdLabelLabel of the threshold line; default "Goal N"
attributeunitUnit appended to values in the accessible text, e.g. " mmHg"; default ""
property / JSON attributelegendArray<{label, tone}>; default none
attributedefault-checked / defaultChecked
property / JSON attributedefault-value / defaultValue
attributeauto-focus / autoFocus