structyl

Chart

stable

A 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

ChartJanFebMarAprMay02.0k4.0k6.0k8.0k

Examples

Bar + Line combined

Combine Chart.Bar and Chart.Line inside Chart.Root. Each series picks from the CSS variable palette automatically.

ChartJanFebMarAprMayJun05.0k10.0k
Revenue
Profit

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.

ChartJanFebMarAprMayJun05.0k10.0k
Revenue

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.

ChartJanFebMarAprMayJun05.0k10.0k
Revenue
Cost
Profit

Area (stacked)

Chart.Area with a shared stackId renders a stacked area chart. fillOpacity controls the fill transparency independently per series.

ChartJanFebMarAprMayJun05.0k10.0k15.0k
Revenue
Cost

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.

Pie chart
Direct
Organic
Referral
Social
Email

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.

ChartJanFebMarAprMayJun050100
Alice
Bob
Carol

Scatter plot

Chart.Scatter maps xKey to the horizontal axis and yKey to the vertical axis. Multiple series are supported inside one Chart.Root.

Chart02040600204060
Products

Radar / Spider

Chart.RadarRoot with PolarGrid, PolarAngleAxis and one or more Radar series. Each row in data represents one axis spoke.

Radar chartSpeedStrengthEnduranceAgilitySkill
Alice
Bob

Heatmap

Chart.Heatmap renders a grid of colored cells. Provide xKey, yKey and valueKey to map your data. Width and height are explicit.

HeatmapMonTueWedThuFri9am10am11am12pm1pm2pm3pm4pm

Treemap

Chart.Treemap uses the squarify algorithm. Top-level items may contain a children array for nested groups. Omit children for a flat treemap.

TreemapEquitiesTechFinanceHealthFixed IncomeGovtCorpReal EstateCommoditiesCash

Funnel

Chart.Funnel renders a top-down funnel. Each stage needs a name and value. Stages are rendered in the order provided.

Funnel chartVisitors10,000 (100.0%)Leads6,500 (65.0%)Prospects3,800 (38.0%)Customers1,200 (12.0%)

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.

Gauge: 72 out of 100CPU Load0100
Gauge: 45 out of 100Memory0100
Gauge: 88 out of 100Disk I/O0100

Candlestick (OHLC)

Chart.Candlestick expects data with open, high, low and close fields. Use upColor / downColor to customise bullish and bearish candle fills.

Candlestick chart90.00100.00110.00120.00130.00MonTueWedThuFriMonTueWed

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.

Line
Bar

RangeBar

Chart.RangeBar renders floating bars that span from lowKey to highKey. Use it for temperature ranges, confidence intervals or availability windows.

ChartJanFebMarAprMayJun050100
Temp range (°C)

ReferenceLine

Chart.ReferenceLine draws a horizontal (y) or vertical (x) rule across the plot area. Use it to mark thresholds, averages or target values.

ChartJanFebMarAprMayJun05.0k10.0kTarget
Revenue

ReferenceArea

Chart.ReferenceArea shades a rectangular region of the chart bounded by y1/y2 (or x1/x2). Combine with ReferenceLine to highlight acceptable ranges.

ChartJanFebMarAprMayJun05.0k10.0kMinMax
Revenue

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.

Radial bar chartTask ATask BTask CTask D

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.

Waterfall chart+120Q1 Start+45Sales-18Returns-25Marketing+15Savings+0Q2 End-50050100150200

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).

Sankey diagramABCDE

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.

Pyramid chartAction1,800Decision3,200Interest6,500Awareness10,000

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.

Gantt chartDesignDesignDevelopmentDevelopmentTestingTestingLaunchLaunch-505101520

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.

Histogram8.018.328.538.849.059.369.579.890.00246

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.

Box plot050100150Q1 SalesQ2 SalesQ3 SalesQ4 Sales

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.

Chord diagramABCD

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.

Sunburst chartRootTechFrontendBackendDevOpsSalesDirectPartnersMarketingDigitalEvents

Linear gauge

Chart.LinearGauge is a horizontal progress-bar style gauge. Use colorStops to apply a traffic-light palette — each stop is [percentage, color].

Gauge: 25 of 100Low (25%)
Gauge: 55 of 100Mid (55%)
Gauge: 85 of 100High (85%)

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.

Radial line chart

Range area

Chart.RangeArea fills the band between a low and high series. Use it for confidence intervals, temperature ranges, or min/max envelopes.

ChartJanFebMarAprMayJunJulAugSepOctNovDec050100
Temperature (°C)

Gauge composition

Compose a gauge from GaugeContainer + GaugeReferenceArc + GaugeValueArc + GaugePointer for full control over colors, thickness and pointer style.

Score: 65 of 100

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 chart

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 chart39%25%17%12%7%

Pie center label

Combine a donut (innerRadius > 0) with Chart.PieCenterLabel to render arbitrary content — text, icons or KPI values — in the hollow center.

Pie chart
8,300
Total
Direct
Organic
Referral
Social
Email

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.

ChartJanFebMarAprMayJun05.0k10.0k420058003900710064008300
Revenue

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.

ChartJanFebMarAprMayJunJulAug-2002040

Funnel variants

Chart.Funnel supports a variant prop (filled / outlined) and a curve prop (linear / bump / step). Combine them for different visual styles.

Outlined

Funnel chartVisitors10,000 (100.0%)Leads6,500 (65.0%)Prospects3,800 (38.0%)Customers1,200 (12.0%)

Bump curve

Funnel chartVisitors10,000 (100.0%)Leads6,500 (65.0%)Prospects3,800 (38.0%)Customers1,200 (12.0%)

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

bash
pnpm dlx structyl add chart

API Reference

Chart.Root

Cartesian chart container. Compose Bar, Line, Area, Scatter and Bubble inside.

PropTypeDefault
dataRecord<string, unknown>[]

Array of data objects.

heightnumber

SVG height in pixels.

300
widthnumber

SVG width. Omit for responsive layout.

margin{ top, right, bottom, left }

Inner margin for axes.

{ top:10, right:10, bottom:30, left:40 }
accessibilityLabelstring

Sets aria-label on the SVG.

accessibilityModeboolean

Enables pattern fills for colorblind accessibility.

false

Chart.Bar

Vertical (or horizontal) bar series inside Chart.Root.

PropTypeDefault
dataKeystring

Required. Field name in data.

namestring

Display name in legend and tooltip.

colorstring

Override color.

stackIdstring

Bars with the same stackId are stacked.

radiusnumber

Corner radius.

2
orientation'vertical' | 'horizontal'

Bar direction.

'vertical'

Chart.Line

Line series inside Chart.Root.

PropTypeDefault
dataKeystring

Required. Field name in data.

namestring

Display name.

colorstring

Override color.

curve'linear' | 'catmullRom' | 'step'

Line interpolation.

'linear'
dotboolean

Show data point dots.

true
strokeWidthnumber

Line stroke width.

2

Chart.Area

Filled area series inside Chart.Root. Accepts all Chart.Line props plus fillOpacity and stackId.

PropTypeDefault
dataKeystring

Required. Field name in data.

fillOpacitynumber

Fill transparency (0–1).

0.2
stackIdstring

Areas with the same stackId are stacked.

Chart.Pie / Chart.PieRoot

Pie or donut chart. Wrap Chart.Pie in Chart.PieRoot.

PropTypeDefault
dataKeystring

Required. Numeric value field.

nameKeystring

Label field for segments.

innerRadiusnumber

Inner radius (> 0 = donut).

0
padAnglenumber

Gap between segments in radians.

cornerRadiusnumber

Rounded segment corners.

colorsstring[]

Per-segment color overrides.

Chart.Radar / Chart.RadarRoot

Radar/spider chart. Wrap Chart.Radar(s) in Chart.RadarRoot.

PropTypeDefault
dataKeystring

Required. Numeric value field to plot.

namestring

Display name.

colorstring

Override color.

fillOpacitynumber

Fill transparency.

0.25

Chart.Heatmap

Standalone heatmap grid. xKey, yKey and valueKey map data fields to cells.

PropTypeDefault
dataRecord<string, unknown>[]

Required.

xKeystring

Required. Horizontal axis field.

yKeystring

Required. Vertical axis field.

valueKeystring

Required. Numeric intensity field.

widthnumber

SVG width.

500
heightnumber

SVG height.

280

Chart.Treemap

Standalone treemap using the squarify algorithm. Supports nested children.

PropTypeDefault
dataTreemapNode[]

Required. Hierarchical data with name, value and optional children.

widthnumber

SVG width.

500
heightnumber

SVG height.

350

Chart.Funnel

Standalone funnel chart rendered top-down.

PropTypeDefault
data{ name: string; value: number }[]

Required. Stages in descending order.

widthnumber

SVG width.

400
heightnumber

SVG height.

300

Chart.Gauge

Standalone half-circle arc gauge.

PropTypeDefault
valuenumber

Required. Current value.

minnumber

Minimum value.

0
maxnumber

Maximum value.

100
widthnumber

SVG width.

240
heightnumber

SVG height.

180
labelstring

Text shown in center of arc.

Chart.Candlestick

Standalone OHLC candlestick chart.

PropTypeDefault
dataOhlcEntry[]

Required. Objects with open, high, low, close.

widthnumber

SVG width.

600
heightnumber

SVG height.

300
bullColorstring

Color for bullish (close > open) candles.

hsl(var(--chart-2))
bearColorstring

Color for bearish (close < open) candles.

hsl(var(--chart-5))
Chart | structyl