Display · Chartsstable
Charts
Chart pieces for comparing numbers at a glance: DonutChart (full ring or semicircle, three sizes), ChartLegend and ChartTooltip, using the categorical chart colours.
Preview
#previewChange the options and the code follows. Show code opens the React snippet.
3,912
Orders
charts-example.tsx
import { DonutChart } from "@blade-ai/weft/components/charts";
<DonutChart
data={[
{ label: "Card", value: 1565 },
{ label: "UPI", value: 1174 },
{ label: "Netbanking", value: 782 },
{ label: "Wallet", value: 391 },
]}
centerValue="3,912"
centerLabel="Orders"
accessibilityLabel="Orders by payment method"
/>All states
#all-statesDonut and semicircle in three sizes, legend orientations and tooltip indicators, from the Charts artboard.
Props
#propsRead from the component source. Booleans are is-prefixed. A star marks a required prop.
DonutChart
Prop
Type
Default
Description
data *
ChartDatum[]
—
—
variant
"donut" | "semicircle"
"donut"
Full ring or half ring.
size
"small" | "medium" | "large"
"small"
Outer diameter 160 / 220 / 280px.
centerValue
ReactNode
—
Big figure in the hole, e.g. the total.
centerLabel
ReactNode
—
Caption under the figure.
accessibilityLabel
string
—
Accessible summary of the chart. Defaults to a list of label and value pairs.
formatValue
(value: number) => string
(v) => v.toLocaleString("en-US")
Format values shown in the hover tooltip.
ChartDatum
Prop
Type
Default
Description
label *
string
—
—
value *
number
—
—
color
string
—
CSS colour (a var(--token)). Defaults to the series palette by index.
ChartLegend
Prop
Type
Default
Description
items *
{ label: string; color: string }[]
—
—
orientation
"horizontal" | "vertical"
"horizontal"
—
ChartTooltip
Prop
Type
Default
Description
title
string
—
—
rows *
ChartTooltipRow[]
—
—
ChartTooltipRow
Prop
Type
Default
Description
label *
string
—
—
value *
ReactNode
—
—
color *
string
—
—
indicator
"dot" | "line" | "dashed"
—
dot for bars and slices, line for line series, dashed for forecasts.
Usage
#usageShort rules for choosing and writing charts.
Do
Use a donut for how a total splits into two to five parts; group the long tail into "Other".
Give every chart an accessible summary.
Keep the legend in the same order as the slices.
Don't
Use a donut for a trend over time.
Rely on colour alone to tell slices apart.
Show more than five slices.
Accessibility
#accessibilityThe chart has a text summary and the tooltip names every value.
ARIA
Element
Role / attribute
When
DonutChart
role="img" · aria-label = accessibilityLabel
Defaults to a list of label and value pairs.
Legend
list
Lists series in the same order as the chart.
Tooltip
text rows
Names each value; never colour alone.