Chart

A small line, area or bar plot in plain SVG. Not a charting library — everything here is a scale and a path, which is the right trade for six numbers on a dashboard card.

src/components/ui/chart.tsx

About

From the component's own source, where it was written.

A small plot — line, area, bar, stacked bar or scatter — in plain SVG.

Deliberately not a charting library. Everything here is a scale and a path, and the alternative is 200 kB of dependency for a component that renders six numbers on a dashboard card. When a real chart is needed (brushing, zoom, stacked transitions) reach for a library and use it directly; this covers the shape you actually put beside a Stat.

The plot area is a fixed 100×60 grid stretched by preserveAspectRatio:none, so it fills its container without measuring. Anything that must keep its proportions under that stretch — strokes, dots, text — either sets vector-effect: non-scaling-stroke or is drawn outside the stretched group.

Install

npx astralyx-ui add chart

Usage

import { Chart } from '@/components/ui/chart'

<Chart series={series} labels={months} variant="area" />

Composer

Change the props and the source below follows.

Deploys, Rollbacks
DeploysRollbacks
Props
tsx
<Chart
  series={series}
  labels={months}
  variant="line"
  grid={true}
  axis={true}
/>

Examples

Variants

API

Generated from the source, so it cannot fall behind the code. One table per exported component, then hooks, functions and types.

Chart

Extends Omit<ComponentProps<'figure'>, 'height'>.

PropTypeDefaultDescription
seriesChartSeries[]required{ name, values, color? }. Colours fall back to a palette by index.
labelsstring[]—X labels, rendered below the plot rather than inside the stretched SVG.
variant'line' | 'area' | 'bar' | 'stacked-bar' | 'scatter''line'Bars group per index across series.
heightnumber180—
gridbooleantrueLegend defaults on for more than one series.
axisbooleantrueLegend defaults on for more than one series.
legendboolean—Legend defaults on for more than one series.
minnumber—Pin the scale. Defaults span zero to the highest value, so bar heights stay honest.
maxnumber—Pin the scale. Defaults span zero to the highest value, so bar heights stay honest.
valueFormat(value: number) => stringDEFAULT_VALUE_FORMAT—

Types

ChartSeries

A small plot — line, area, bar, stacked bar or scatter — in plain SVG.

FieldTypeDescription
namestring—
valuesnumber[]—
color?stringAny CSS colour. Falls back to a palette entry by index.

Behaviour

TopicDetailDescription
scaling100×60 viewBoxStretched by preserveAspectRatio:none so it fills its container without measuring; strokes use non-scaling-stroke to stay even under that stretch.