Mushilu-San UI

Search components

PlaygroundStorybookGitHub
Data display

Chart

A bar, line, pie or doughnut chart drawn from a data set, with an accessible name.

Selector: mui-chart

Import
import { Chart } from '@mushilu-san/ui/data-display';
PreviewCode

Loading example…

Overview

Chart draws its data on a canvas, using the data format of Chart.js. type picks the chart kind, and data and options are passed through to it.

The chart is a role="figure" named by label. The drawing itself is not readable by screen readers, so show the key numbers in text or a table next to it.

When to use

  • Showing a trend or a comparison across a few categories or dates.
  • A summary view where the shape of the data matters more than exact values.

When not to use

  • Exact values that users need to read or compare. Use a table. Use Table instead.

Guidelines

Do

  • Give every chart a label that says what it shows and the period.
  • Use colour plus a legend or labels, not colour alone.

Don't

  • Do not use a pie chart for more than about five slices.
  • Do not truncate the value axis of a bar chart.

Accessibility

Roles and attributes

ElementRoleNotes
hostfigurearia-label from label.
  • Provide the same numbers in a table or text summary below the chart.

API

Chart

Selector: mui-chart

NameTypeDefaultDescription
type'bar' | 'line' | 'scatter' | 'bubble' | 'pie' | 'doughnut' | 'polarArea' | 'radar''bar' Chart kind: `bar`, `line`, `pie`, `doughnut`, and other Chart.js types. Default `bar`.
datarequiredChartData<keyof ChartTypeRegistry, (number | [number, number] | Point | BubbleDataPoint | null)[], unknown>— Data set in the Chart.js format: `labels` and `datasets`.
optionsPortableChartOptions— Chart.js options passed through to the chart.
labelstring'Chart' Accessible name of the figure, describing what is shown. Default `Chart`.

CSS parts

  • ::part(canvas)
  • ::part(root)

Tokens

  • --mui-color-primary
  • --mui-color-success
  • --mui-color-warning
  • --mui-color-danger
  • --mui-color-text-muted