Components Data display

Charts

LineChart and BarChart draw one or more series over ordered categories; PieChart draws parts of a whole, as a pie or a donut. A legend, a readout under the pointer, the chart palette tokens or a colour of yours; height="fill" takes the height of its box.

import { LineChart, BarChart, PieChart } from '@kition/tessera-ui'

Examples

Growth by day
VisitorsDownloadsSign-ups
020040060010-1010-1210-1410-1610-1810-2010-22
line-chart.tsx
import { LineChart } from '@kition/tessera-ui'

const days = Array.from({ length: 14 }, (_, index) => `10-${String(index + 10).padStart(2, '0')}`)
const DATA = days.flatMap((date, index) => [
  { date, metric: 'Visitors', value: Math.round(420 + Math.sin(index / 2) * 90 + index * 12) },
  { date, metric: 'Downloads', value: Math.round(120 + Math.cos(index / 3) * 30 + index * 6) },
  { date, metric: 'Sign-ups', value: Math.round(40 + Math.sin(index) * 8 + index * 2) },
])

export default function Demo() {
  return <LineChart label="Growth by day" data={DATA} xField="date" yField="value" seriesField="metric" height={260} />
}
Bars and a donut
0510152025BacklogTo doDoingReviewDone
BacklogTo doDoingReviewDone
bar-pie-chart.tsx
import { BarChart, PieChart } from '@kition/tessera-ui'

const STAGES = [
  { stage: 'Backlog', tasks: 14 },
  { stage: 'To do', tasks: 9 },
  { stage: 'Doing', tasks: 6 },
  { stage: 'Review', tasks: 4 },
  { stage: 'Done', tasks: 21 },
]

export default function Demo() {
  return (
    <div style={{ display: 'grid', gridTemplateColumns: '3fr 2fr', gap: 24 }}>
      <BarChart label="Tasks by stage" data={STAGES} xField="stage" yField="tasks" height={240} />
      <PieChart label="Share of tasks" data={STAGES} labelField="stage" valueField="tasks" innerRadius={0.6} height={200} />
    </div>
  )
}

Props

LineChart

Lines of one or more series over ordered categories, with a legend and a hover readout.

PropTypeDefaultDescription
datarequiredreadonly T[]—
xFieldrequiredkeyof T & string—The field of each datum on the horizontal axis (categories in order of first appearance).
yFieldrequiredkeyof T & string—The field holding the number.
seriesFieldkeyof T & string—The field naming the series a datum belongs to; one series without it.
heightChartHeight—
colorstring—The colour of a single series (the palette's first by default).
integersboolean—Counts: the axis steps only by whole numbers.
formatX(value: string) => string—
formatY(value: number) => string—
labelrequiredstring—The chart's accessible name.
classNamestring—
testIdstring—
dotsboolean—Marks each point with a dot.

BarChart

Bars of one or more series per category, side by side, with rounded tops.

PropTypeDefaultDescription
datarequiredreadonly T[]—
xFieldrequiredkeyof T & string—The field of each datum on the horizontal axis (categories in order of first appearance).
yFieldrequiredkeyof T & string—The field holding the number.
seriesFieldkeyof T & string—The field naming the series a datum belongs to; one series without it.
heightChartHeight—
colorstring—The colour of a single series (the palette's first by default).
integersboolean—Counts: the axis steps only by whole numbers.
formatX(value: string) => string—
formatY(value: number) => string—
labelrequiredstring—The chart's accessible name.
classNamestring—
testIdstring—
maxBarWidthnumber—The widest a bar draws, in px.

PieChart

Parts of a whole as slices of a pie (or a donut), with a legend and a readout of the slice under the pointer.

PropTypeDefaultDescription
datarequiredreadonly T[]—
labelFieldrequiredkeyof T & string—The field naming each slice.
valueFieldrequiredkeyof T & string—The field holding each slice's number.
heightChartHeight240
innerRadiusnumber0The hole's size as a share of the radius (0.6 for a donut); a full pie by default.
colorsreadonly string[]—Colours for the slices, in order; the chart palette by default.
formatValue(value: number) => string(value) => value.toLocaleString()
labelrequiredstring—The chart's accessible name.
classNamestring—
testIdstring—

Used in

1 of Kition's 16 kits use these components.

  • Table