Charts
Sparkline and BarChart render compact SVG charts from a small set of values, built on the d3-scale and d3-shape primitives. Those are external dependencies, so a bundler only pulls them in for the pages that actually use a chart. Both are accessible by default: give them a label (a Sparkline without one is treated as decorative).
vue
<script setup lang="ts">
import { BarChart, Sparkline } from '@myghf/ui'
const waitTimes = [4, 6, 5, 9, 7, 11, 8, 10]
const referrals = [
{ label: 'Cardiology', value: 42 },
{ label: 'Neurology', value: 28 },
]
</script>
<template>
<Sparkline :data="waitTimes" label="Median wait times" />
<BarChart :data="referrals" label="Referrals by unit" />
</template>Examples
| Label | Value |
|---|---|
| Cardiology | 42 |
| Neurology | 28 |
| Oncology | 35 |
| Paediatrics | 19 |
vue
<script setup lang="ts">
import { BarChart, Sparkline } from '@myghf/ui'
const waitTimes = [4, 6, 5, 9, 7, 11, 8, 10]
const referrals = [
{ label: 'Cardiology', value: 42 },
{ label: 'Neurology', value: 28 },
{ label: 'Oncology', value: 35 },
{ label: 'Paediatrics', value: 19 },
]
</script>
<template>
<div class="grid gap-6">
<div class="flex flex-wrap items-center gap-4">
<Sparkline :data="waitTimes" label="Median wait times" />
<Sparkline :data="waitTimes" type="area" tone="success" label="Median wait times" />
<Sparkline :data="waitTimes" type="area" tone="danger" :width="160" :height="40" label="Median wait times" />
</div>
<BarChart :data="referrals" label="Referrals by unit" />
</div>
</template>Sparkline
A compact line or area chart for a single series, sized for table cells, metric cards, and trend columns.
| Prop | Type | Default | Description |
|---|---|---|---|
data | number[] | — | The series, in order. |
type | 'line' | 'area' | 'line' | Draw a stroked line or a filled area. |
width | number | 120 | SVG width in pixels. |
height | number | 32 | SVG height in pixels. |
tone | 'info' | 'success' | 'warning' | 'danger' | 'secondary' | 'info' | Line/area colour. |
label | string | — | Accessible name. When omitted the sparkline is decorative (aria-hidden). |
BarChart
A categorical bar chart with a screen-reader table of the same values.
| Prop | Type | Default | Description |
|---|---|---|---|
data | { label: string; value: number }[] | — | The categories and their values. |
width | number | 320 | SVG width in pixels. |
height | number | 160 | SVG height in pixels. |
tone | tone | 'info' | Bar colour. |
label | string | — (required) | Accessible name for the chart. |
Accessibility
Sparklineisrole="img"with thelabelas its name; without alabelit isaria-hidden="true", so a purely decorative trend does not clutter the accessibility tree.BarChartexposes the chart as a namedrole="img"and a visually-hidden<table>with the same labels and values, so screen readers can read the data rather than only a summary.- Both are non-interactive graphics; put a heading or caption nearby when the chart needs context, and keep an accessible name short.
Dark mode & RTL
- Colour comes from the tone (
text-primary-500etc.) viacurrentColor, so the charts adapt to dark mode automatically. - The graphics are direction-neutral (values map to a fixed horizontal axis), so there is no RTL variant; mirror an axis yourself if a chart must follow the writing direction.
