Components
Chart
Areas, lines and bars on one axis, a donut and an allocation bar: plain SVG that draws itself in, with a crosshair tooltip, keyboard reading, a legend and a table for screen readers.
- Balance
- Projected
| month | Balance | Projected |
|---|---|---|
| Apr | ₹4.2L | |
| May | ₹5.1L | |
| Jun | ₹3.8L | |
| Jul | ₹4.6L | |
| Aug | ₹6.2L | |
| Sept | ₹7.1L | ₹7.1L |
| Oct | ₹6.4L | |
| Nov | ₹7.9L | |
| Dec | ₹8.8L | |
| Jan | ₹7.6L | |
| Feb | ₹9.4L | |
| Mar | ₹10.2L |
Import
import { Chart, ChartArea, ChartLine, ChartBar, ChartReference, ChartTooltipCard, DonutChart, AllocationBar } from '@rinzai/zen';Examples
Cashflow
Bars grouped by month with a line on the same axis; months still to come are faded.
- Income
- Spending
- Net
| month | Income | Spending | Net |
|---|---|---|---|
| Apr | ₹92K | ₹61K | ₹31K |
| May | ₹92K | ₹74K | ₹18K |
| Jun | ₹98K | ₹58K | ₹40K |
| Jul | ₹98K | ₹1L | -₹5K |
| Aug | ₹98K | ₹66K | ₹32K |
| Sep | ₹1.1L | ₹71K | ₹41K |
| Oct | ₹1.1L | ₹69K | ₹43K |
| Nov | ₹1.1L | ₹80K | ₹32K |
Lines
Several series in the chart palette, in the order they're written; the legend appears for two or more.
- Web
- iOS
- Android
| day | Web | iOS | Android |
|---|---|---|---|
| Mon | 420 | 310 | 220 |
| Tue | 480 | 330 | 260 |
| Wed | 510 | 360 | 250 |
| Thu | 470 | 390 | 300 |
| Fri | 560 | 380 | 330 |
| Sat | 690 | 450 | 310 |
| Sun | 640 | 470 | 360 |
Donut
Parts of a whole with the total in the middle, and a legend of your own beside it, in the chart's colours (paletteColor).
- Home₹28,000
- Food₹14,500
- Travel₹9,200
- Fun₹6,100
- Other₹3,400
Allocation
Where September's income went.
API reference
<Chart>
A chart on one axis: areas, lines and bars over rows of data (e.g. months), with a recessive grid, a crosshair and a tooltip listing every series at the pointer (or keyboard: focus it and use the arrow keys), a legend for two or more series, and a table of the values for screen readers. Series draw in as they appear. Colours default to the chart palette (--chart-1…8) in the order the series are written; give each its own color for meaning (e.g. the theme's glow).
| Prop | Type | Default |
|---|---|---|
childrenRequiredChartArea, ChartLine, ChartBar and ChartReference parts. | ReactNode | — |
dataRequiredOne row per point on the x axis (e.g. a month). | readonly T[] | — |
labelRequiredNames the chart for screen readers. | string | — |
xRequiredThe row field placed along the x axis. | string | — |
className | string | — |
formatTooltipXThe tooltip's title for an x value (defaults to formatX). | ((value: T[X]) => string) | — |
formatXAxis labels for x values. | ((value: T[X]) => string) | — |
formatYAxis ticks and tooltip values (defaults to compact numbers: 1.2K). | ((value: number) => string) | (n: number) => compactFormat.format(n) |
heightHeight in px, including the axis labels. | number | 240 |
legendShow the legend. Defaults to on for two or more series, or a bar's | boolean | — |
paletteColours for series that don't give their own: the categorical palette (default), or shades of the theme's glow. | ChartPalette | chart |
renderTooltipYour own tooltip for a row (build it from ChartTooltipCard). | ((row: T, index: number) => ReactNode) | — |
summaryA sentence on what the chart shows, for screen readers (e.g. its highest and lowest points). | string | — |
<ChartArea>
A line with a soft fill down to the baseline.
| Prop | Type | Default |
|---|---|---|
dataKeyRequiredThe row field holding this series' values (numbers; null for none). | string | — |
labelRequiredIts name in the legend, the tooltip and the table. | string | — |
colorAny CSS colour. Defaults to the next of --chart-1…8. | string | — |
curveSmooth (default) or straight between points. | "linear" | "monotone" | — |
dashedDashed (e.g. a projection). | boolean | — |
<ChartLine>
A 2px line. Gaps (null values) break it, so one series can be split into solid and dashed parts.
| Prop | Type | Default |
|---|---|---|
dataKeyRequiredThe row field holding this series' values (numbers; null for none). | string | — |
labelRequiredIts name in the legend, the tooltip and the table. | string | — |
colorAny CSS colour. Defaults to the next of --chart-1…8. | string | — |
curveSmooth (default) or straight between points. | "linear" | "monotone" | — |
dashedDashed (e.g. a projection). | boolean | — |
<ChartBar>
Bars, grouped with the other bar series, growing from the baseline.
| Prop | Type | Default |
|---|---|---|
dataKeyRequiredThe row field holding this series' values (numbers; null for none). | string | — |
labelRequiredIts name in the legend, the tooltip and the table. | string | — |
colorAny CSS colour. Defaults to the next of --chart-1…8. | string | — |
dimRows whose bar is faded, e.g. months still to come. | ((row: Row, index: number) => boolean) | — |
dimLabelWhat the faded bars mean, e.g. "Planned": the legend gets a faded key for it (and shows, even for one series). | string | — |
<ChartReference>
A marker across the plot: a horizontal line at y (e.g. zero), or a vertical one at the row whose x is x (e.g. today).
| Prop | Type | Default |
|---|---|---|
dashedVertical lines are dashed unless | boolean | — |
labelText beside a vertical line, e.g. "Today". | string | — |
toneDestructive for a line that warns (e.g. below zero). | "muted" | "negative" | — |
xA vertical line at the row whose x field equals this. | unknown | — |
yA horizontal line at this value. | number | — |
<ChartTooltipCard>
The tooltip's card: a title and one row per series, the value first and the series keyed by a short stroke of its colour. Use it in renderTooltip to show your own rows.
| Prop | Type | Default |
|---|---|---|
rowsRequired | { label: string; value: string; color?: string | undefined; dashed?: boolean | undefined; }[] | — |
titleRequired | ReactNode | — |
className | string | — |
<DonutChart>
A ring of parts of a whole (e.g. spending by category), with your content in the middle (e.g. the total). Segments are parted by a small gap, with rounded corners; pointing at one (or focusing it) lifts it and shows its value. A part too small to show at its share is drawn as a pill, the narrowest segment, taking the room from the larger parts in proportion. Best for a handful of parts: past about six, use bars. Colours default to the chart palette in order.
| Prop | Type | Default |
|---|---|---|
itemsRequiredThe parts, in order round the ring from 12 o'clock. | { key: string; label: string; value: number; color?: string | undefined; }[] | — |
labelRequiredNames the chart for screen readers. | string | — |
childrenContent in the middle, e.g. the total. | ReactNode | — |
className | string | — |
formatValueValues in the tooltip and for screen readers. | ((value: number) => string) | — |
paletteColours for items that don't give their own: the categorical palette (default), or shades of the theme's glow. | ChartPalette | chart |
sizeDiameter in px. | number | 200 |
thicknessRing thickness as a share of the radius. | number | 0.32 |
<AllocationBar>
Where a whole went, as one bar split into its parts (e.g. income across spending, savings and bills), with a legend of each part's value and share. Pointing at a part, in the bar or the legend, picks it out; screen readers hear every part's value and share from the bar's label. Sweeps in from the start the first time it's seen. Colours default to the chart palette in order, like DonutChart's.
| Prop | Type | Default |
|---|---|---|
itemsRequired | AllocationItem[] | — |
labelRequiredWhat the whole is, e.g. "Income in September", for screen readers. | string | — |
className | string | — |
formatValue | ((value: number) => string) | — |
legendThe list of parts under the bar (default on). | boolean | true |
localeFor the shares' percent format. | string | — |
paletteColours for items that don't give their own: the categorical palette (default), or shades of the theme's glow. | ChartPalette | chart |