Chart
stableA comprehensive custom SVG chart library with 45+ components — bar, line, area, pie/donut, scatter, bubble, radar, heatmap, treemap, funnel, gauge, candlestick, radial bar, radial line, sankey, waterfall, gantt, boxplot, sunburst, chord, histogram, and more. No external charting dependency.
Basic usage
Examples
Bar + Line combined
Combine Chart.Bar and Chart.Line inside Chart.Root. Each series picks from the CSS variable palette automatically.
Bar chart
A vertical bar chart with grid lines, labelled axes and an interactive tooltip. The chart is responsive — omit the width prop to let it fill its container.
Multi-series (Bar + Line)
Combine Chart.Bar and Chart.Line inside the same Chart.Root to overlay series with different mark types. The stacked bars use the same stackId.
Area (stacked)
Chart.Area with a shared stackId renders a stacked area chart. fillOpacity controls the fill transparency independently per series.
Pie / Donut
Wrap Chart.Pie in Chart.PieRoot. Set innerRadius > 0 to make a donut chart. padAngle and cornerRadius add spacing and rounded corners between segments.
Line (multi-series)
Multiple Chart.Line components inside one Chart.Root. Each series picks the next color from the palette automatically, or accepts an explicit color prop.
Scatter plot
Chart.Scatter maps xKey to the horizontal axis and yKey to the vertical axis. Multiple series are supported inside one Chart.Root.
Radar / Spider
Chart.RadarRoot with PolarGrid, PolarAngleAxis and one or more Radar series. Each row in data represents one axis spoke.
Heatmap
Chart.Heatmap renders a grid of colored cells. Provide xKey, yKey and valueKey to map your data. Width and height are explicit.
Treemap
Chart.Treemap uses the squarify algorithm. Top-level items may contain a children array for nested groups. Omit children for a flat treemap.
Funnel
Chart.Funnel renders a top-down funnel. Each stage needs a name and value. Stages are rendered in the order provided.
Gauge
Chart.Gauge renders a half-circle arc gauge. Use the label prop to annotate the center. Combine multiple gauges side by side for a dashboard widget.
Candlestick (OHLC)
Chart.Candlestick expects data with open, high, low and close fields. Use upColor / downColor to customise bullish and bearish candle fills.
SparkLine
Chart.SparkLine is a standalone mini-chart designed to fit inside table cells, cards or KPI widgets. Use type="line" (default) or type="bar". Width and height are explicit.
RangeBar
Chart.RangeBar renders floating bars that span from lowKey to highKey. Use it for temperature ranges, confidence intervals or availability windows.
ReferenceLine
Chart.ReferenceLine draws a horizontal (y) or vertical (x) rule across the plot area. Use it to mark thresholds, averages or target values.
ReferenceArea
Chart.ReferenceArea shades a rectangular region of the chart bounded by y1/y2 (or x1/x2). Combine with ReferenceLine to highlight acceptable ranges.
Radial bar
Wrap Chart.RadialBar in Chart.RadialBarRoot. Each row in data becomes a concentric arc ring. Provide dataKey for arc length and nameKey for labels.
Waterfall
Chart.Waterfall renders a bridge / waterfall chart where each bar starts from the running total of the previous bars. Negative values are styled differently.
Sankey
Chart.Sankey visualises flow between nodes using proportional-width links. Provide a nodes array (id + optional color) and a links array (source, target, value).
Pyramid
Chart.Pyramid is an inverted funnel — the widest segment is at the bottom. Use it for hierarchical data or population pyramids where the largest value is the base.
Gantt
Chart.Gantt renders a horizontal timeline where each task bar spans from start to end on a numeric time axis. Add a group field to visually cluster related tasks.
Histogram
Chart.Histogram bins a flat array of numbers into equal-width buckets and renders them as a bar chart. Use bins to control the number of buckets.
Boxplot
Chart.Boxplot renders standard box-and-whisker plots. Each entry needs min, q1, median, q3 and max. Add an outliers array for individual outlier dots.
Chord diagram
Chart.Chord visualises relationships between groups using a square matrix. Each cell [i][j] is the flow strength from group i to group j.
Sunburst
Chart.Sunburst renders a multi-level donut chart. Pass a nested data tree — each node can have a value (leaf) or children (branch). Click a segment to zoom in.
Linear gauge
Chart.LinearGauge is a horizontal progress-bar style gauge. Use colorStops to apply a traffic-light palette — each stop is [percentage, color].
Radial line
Chart.RadialLineRoot + Chart.RadialLine plots data on a circular axis — useful for cyclic data like months or weekdays. Use closePath and area for a spider-web fill.
Range area
Chart.RangeArea fills the band between a low and high series. Use it for confidence intervals, temperature ranges, or min/max envelopes.
Gauge composition
Compose a gauge from GaugeContainer + GaugeReferenceArc + GaugeValueArc + GaugePointer for full control over colors, thickness and pointer style.
Semi-circle pie
Restrict the arc sweep with startAngle and endAngle to produce a semi-circle pie. Any angular range is supported — not just a full 360°.
Pie arc labels
Set arcLabel="percentage" to render the percentage of total directly on each arc segment. Use arcLabelMinAngle to suppress labels on tiny slices.
Pie center label
Combine a donut (innerRadius > 0) with Chart.PieCenterLabel to render arbitrary content — text, icons or KPI values — in the hollow center.
Bar with labels
Enable showLabel on Chart.Bar to print the value on every bar. Use labelPosition="outside" to place the label above the bar, inside to place it within.
Area fill by value
Set fillByValue on Chart.Area to automatically use the chart-1 color above zero and the chart-3 color below zero — useful for P&L or delta charts.
Funnel variants
Chart.Funnel supports a variant prop (filled / outlined) and a curve prop (linear / bump / step). Combine them for different visual styles.
Outlined
Bump curve
Features
- 20+ chart types with 45+ composable components.
- Every chart type has multiple variants (stacked, horizontal, arc labels, fill-by-value, etc.).
- Fully responsive cartesian charts via ResizeObserver.
- CSS variable color system (--chart-1 through --chart-5).
- Colorblind-safe accessibilityMode with SVG pattern fills.
- Compound Chart.* API — composable and tree-shakeable.
- No Recharts, Chart.js or D3 dependency — pure SVG.
Installation
pnpm dlx structyl add chartAPI Reference
Chart.Root
Cartesian chart container. Compose Bar, Line, Area, Scatter and Bubble inside.
| Prop | Type | Default |
|---|---|---|
| data | Record<string, unknown>[]Array of data objects. | — |
| height | numberSVG height in pixels. | 300 |
| width | numberSVG width. Omit for responsive layout. | — |
| margin | { top, right, bottom, left }Inner margin for axes. | { top:10, right:10, bottom:30, left:40 } |
| accessibilityLabel | stringSets aria-label on the SVG. | — |
| accessibilityMode | booleanEnables pattern fills for colorblind accessibility. | false |
Chart.Bar
Vertical (or horizontal) bar series inside Chart.Root.
| Prop | Type | Default |
|---|---|---|
| dataKey | stringRequired. Field name in data. | — |
| name | stringDisplay name in legend and tooltip. | — |
| color | stringOverride color. | — |
| stackId | stringBars with the same stackId are stacked. | — |
| radius | numberCorner radius. | 2 |
| orientation | 'vertical' | 'horizontal'Bar direction. | 'vertical' |
Chart.Line
Line series inside Chart.Root.
| Prop | Type | Default |
|---|---|---|
| dataKey | stringRequired. Field name in data. | — |
| name | stringDisplay name. | — |
| color | stringOverride color. | — |
| curve | 'linear' | 'catmullRom' | 'step'Line interpolation. | 'linear' |
| dot | booleanShow data point dots. | true |
| strokeWidth | numberLine stroke width. | 2 |
Chart.Area
Filled area series inside Chart.Root. Accepts all Chart.Line props plus fillOpacity and stackId.
| Prop | Type | Default |
|---|---|---|
| dataKey | stringRequired. Field name in data. | — |
| fillOpacity | numberFill transparency (0–1). | 0.2 |
| stackId | stringAreas with the same stackId are stacked. | — |
Chart.Pie / Chart.PieRoot
Pie or donut chart. Wrap Chart.Pie in Chart.PieRoot.
| Prop | Type | Default |
|---|---|---|
| dataKey | stringRequired. Numeric value field. | — |
| nameKey | stringLabel field for segments. | — |
| innerRadius | numberInner radius (> 0 = donut). | 0 |
| padAngle | numberGap between segments in radians. | — |
| cornerRadius | numberRounded segment corners. | — |
| colors | string[]Per-segment color overrides. | — |
Chart.Radar / Chart.RadarRoot
Radar/spider chart. Wrap Chart.Radar(s) in Chart.RadarRoot.
| Prop | Type | Default |
|---|---|---|
| dataKey | stringRequired. Numeric value field to plot. | — |
| name | stringDisplay name. | — |
| color | stringOverride color. | — |
| fillOpacity | numberFill transparency. | 0.25 |
Chart.Heatmap
Standalone heatmap grid. xKey, yKey and valueKey map data fields to cells.
| Prop | Type | Default |
|---|---|---|
| data | Record<string, unknown>[]Required. | — |
| xKey | stringRequired. Horizontal axis field. | — |
| yKey | stringRequired. Vertical axis field. | — |
| valueKey | stringRequired. Numeric intensity field. | — |
| width | numberSVG width. | 500 |
| height | numberSVG height. | 280 |
Chart.Treemap
Standalone treemap using the squarify algorithm. Supports nested children.
| Prop | Type | Default |
|---|---|---|
| data | TreemapNode[]Required. Hierarchical data with name, value and optional children. | — |
| width | numberSVG width. | 500 |
| height | numberSVG height. | 350 |
Chart.Funnel
Standalone funnel chart rendered top-down.
| Prop | Type | Default |
|---|---|---|
| data | { name: string; value: number }[]Required. Stages in descending order. | — |
| width | numberSVG width. | 400 |
| height | numberSVG height. | 300 |
Chart.Gauge
Standalone half-circle arc gauge.
| Prop | Type | Default |
|---|---|---|
| value | numberRequired. Current value. | — |
| min | numberMinimum value. | 0 |
| max | numberMaximum value. | 100 |
| width | numberSVG width. | 240 |
| height | numberSVG height. | 180 |
| label | stringText shown in center of arc. | — |
Chart.Candlestick
Standalone OHLC candlestick chart.
| Prop | Type | Default |
|---|---|---|
| data | OhlcEntry[]Required. Objects with open, high, low, close. | — |
| width | numberSVG width. | 600 |
| height | numberSVG height. | 300 |
| bullColor | stringColor for bullish (close > open) candles. | hsl(var(--chart-2)) |
| bearColor | stringColor for bearish (close < open) candles. | hsl(var(--chart-5)) |