Skip to content
Skip to Content
ComposerKit
Guides

Charts

Build SVG and WebGL charts with zoom, sampling, keyboard focus, semantic chart tokens, and image, print, or Excel export.

@composerkit/charts provides declarative React charts built on one shared frame, keyboard navigation model, and token palette.

Install it into your app with:

npx shadcn add @composerkit/charts --overwrite --yes

Chart families

Component or helperSeries and use cases
CartesianChartMixed bar, line, scatter, rangeBar, ohlc (candlestick), and heatmap series on one x and y axis, horizontal or vertical layouts, stacking, and area fills.
PieChartPie and donut slices (innerRadius, paddingAngle, arcLabel).
RadialBarChart, RadialLineChartCircular category bars (rings or spokes) and radial line/area series.
RadarChartMulti-metric comparison across circular or polygonal axes with per-metric min/max.
FunnelChartLinear, sharp, bump, step, and pyramid flows (curve, direction="auto", sectionSize="value").
SankeyChartFlow diagrams from links and optional nodes with nodeAlign and cycle detection.
GaugeSingle-value arc meter (valueMin, valueMax, startAngle, endAngle) backed by a native meter for assistive tech.
SparkLineChartInline word-sized line, area, or bar chart with optional hover tooltip and highlight.
waterfallSeriesHelper converting incremental changes and totals into a colored rangeBar series.
ChartsRendererRenders table-shaped dimensions and value columns as column, bar, line, area, or pie charts.

Standalone charts vs data-grid charts

NeedPackageEngineWhy
Dashboards, reports, analytics pages, SVG/WebGL interactivity@composerkit/chartsDeclarative SVG + optional WebGL2Supports full chart families, DOM/keyboard focus, zoom slider, sampling, and CSS token styling.
Range charts and cell sparklines inside TableCore@composerkit/data-gridIsolated chart.js <canvas>Keeps synchronous getChartImageDataURL() for Excel PNG embedding and tight cell rendering.

Renderers, zoom, and sampling

  • renderer="svg" (default): renders marks as accessible SVG nodes with hover and keyboard focus.
  • renderer="svg-batch": groups bar and scatter marks into one SVG <path> per series and highlight state to cut DOM node counts.
  • renderer="webgl": draws bars, range bars, candlesticks, heatmap cells, and scatter points on one WebGL2 canvas while keeping axes, lines, tooltips, and keyboard focus in SVG. Automatically restores on WebGL context loss.
  • zoom: enables wheel zoom around the pointer, drag panning, and an interactive range slider. Focused charts support + / - (zoom 10%), Shift+ArrowLeft / Shift+ArrowRight (pan 10%), and 0 (reset). Control externally with zoomData, onZoomChange, and apiRef.current.setZoomData().
  • sampling: downsamples dense series (bars narrower than 6px or over 2,000 points) into power-of-two buckets using minmax or lttb. Zooming in reveals raw points automatically.

Export and Content Security Policy

Pass exportMenu to enable downloads from the chart toolbar or call apiRef.current directly:

  • Excel (exportMenu={{ excel: {} }}): writes one sheet per series type via @composerkit/excel (getDataAsExcel(), exportAsExcel()). Hidden series stay excluded unless includeHiddenSeries is set.
  • Image (image): renders the full chart and legend to PNG, JPEG, or WebP (exportAsImage()).
  • Print (print): opens the browser print dialog for paper or Save as PDF (exportAsPrint()).
  • CSP compliance: exports clone page styles into a hidden frame. Under a strict CSP, pass nonce or set copyStyles: false. Blocked styles throw ChartExportStyleError, and unreadable cross-origin stylesheets invoke onStylesheetError.

Keyboard and tokens

Every chart surface is one Tab stop. Arrow keys move along and across series, Home and End jump to series bounds, Escape clears focus, and Enter or Space fires onItemClick. Focused items announce through a polite live region.

Charts read their default colors from --chart-1 through --chart-6, --chart-up, --chart-down, --chart-heat-low, and --chart-heat-high, all defined in packages/composerkit/DESIGN.md.

Known limits

  • One x axis and one y axis per cartesian chart; zoom operates on the x axis only.
  • svg-batch batches rectangles and circles only; lines, candlesticks, and heatmap cells remain individual nodes.
  • Exported raster images fall back to system fonts because browsers rasterize detached SVG without loading remote web fonts.
  • WebGL heatmap interpolation runs in sRGB whereas SVG cells mix in OKLab, so intermediate shades can differ slightly.

Continue to the Charts component reference for live demos and generated TypeScript props.

On this page