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
Plain
Tall
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
| Variant | What it is |
|---|---|
| default | primary bars. |
| tones | hi (danger), lo (warning), ok (success), ai, accent. |
| threshold | Dashed goal line with label. |
| legend | Explains 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
| Prop | Type | Default | Description |
|---|---|---|---|
data * | BarChartDatum[] | — | Array<{label, value, tone?}> |
title | string | none | Caption above the chart and start of the accessible summary |
height | number | 150 | Plot height in px |
max | number | auto (largest value) | Top of the scale |
threshold | number | none | Value of the dashed goal or limit line |
thresholdLabel | string | "Goal N" | Label of the threshold line |
unit | string | "" | Unit appended to values in the accessible text, e.g. " mmHg" |
legend | BarChartLegendItem[] | none | Array<{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>
| Kind | Name | Description |
|---|---|---|
| property / JSON attribute | data | Array<{label, value, tone?}> |
| attribute | title | Caption above the chart and start of the accessible summary; default none |
| attribute | height | Plot height in px; default 150 |
| attribute | max | Top of the scale; default auto (largest value) |
| attribute | threshold | Value of the dashed goal or limit line; default none |
| attribute | threshold-label / thresholdLabel | Label of the threshold line; default "Goal N" |
| attribute | unit | Unit appended to values in the accessible text, e.g. " mmHg"; default "" |
| property / JSON attribute | legend | Array<{label, tone}>; default none |
| attribute | default-checked / defaultChecked | |
| property / JSON attribute | default-value / defaultValue | |
| attribute | auto-focus / autoFocus |