Components
Chart
Areas, lines and bars on one axis, and a donut: 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 } 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.
- Home₹28,000
- Food₹14,500
- Travel₹9,200
- Fun₹6,100
- Other₹3,400
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. | boolean | — |
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) | — |
<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). | "destructive" | "muted" | — |
xA vertical line at the row whose x field equals this. | unknown | — |
yA horizontal line at this value. | number | — |
<ChartTooltipCard>
No props of its own; it accepts the props of the element it renders.
<DonutChart>
No props of its own; it accepts the props of the element it renders.