TanStack Charts 0.4.0 is a pre-alpha release. Its API may change between releases.
TanStack Charts is a small, framework-agnostic chart grammar for TypeScript and JavaScript. Give each mark its natural data, map fields or accessors to visual channels, and supply the D3 scales that define the meaning of each axis. TanStack Charts compiles that declaration into a responsive, keyed scene and renders accessible SVG by default, with Canvas available as an opt-in surface.
TanStack Charts builds on the grammar-of-graphics tradition established by Leland Wilkinson and developed through projects such as ggplot2, Vega-Lite, and Observable Plot. Observable Plot is the closest API influence for mark-local data, channels, and layered composition. TanStack Charts applies those ideas to typed application infrastructure with explicit D3 primitives, responsive scene compilation, and framework lifecycle.
The library is designed for two equally important authors:
The same definition can feed the vanilla DOM host and framework adapters. React and Octane also provide optional Canvas entries; the experimental React Native adapter consumes definitions from the universal entry.
import { mean } from 'd3-array'
import { scaleLinear, scaleUtc } from 'd3-scale'
import { areaY, defineChart, lineY } from '@tanstack/charts'
interface ClosingPrice {
Date: Date
Close: number
}
const observations: readonly ClosingPrice[] = [
{ Date: new Date('2013-05-13T00:00:00Z'), Close: 64.96 },
{ Date: new Date('2013-05-14T00:00:00Z'), Close: 63.41 },
{ Date: new Date('2013-05-15T00:00:00Z'), Close: 61.26 },
{ Date: new Date('2013-05-16T00:00:00Z'), Close: 62.08 },
{ Date: new Date('2013-05-17T00:00:00Z'), Close: 61.89 },
{ Date: new Date('2013-05-20T00:00:00Z'), Close: 63.28 },
{ Date: new Date('2013-05-21T00:00:00Z'), Close: 62.81 },
{ Date: new Date('2013-05-22T00:00:00Z'), Close: 63.05 },
]
const rows = observations.flatMap((row, index) => {
if (index < 2) return []
const average = mean(
observations.slice(index - 2, index + 1),
(observation) => observation.Close,
)
return average === undefined ? [] : [{ ...row, average }]
})
const closingPriceChart = defineChart({
marks: [
areaY(rows, {
x: 'Date',
y1: 'average',
y2: 'Close',
fill: '#2563eb',
fillOpacity: 0.18,
}),
lineY(rows, {
x: 'Date',
y: 'Close',
stroke: '#2563eb',
}),
lineY(rows, {
x: 'Date',
y: 'average',
stroke: '#64748b',
}),
],
x: {
scale: scaleUtc,
nice: true,
axis: { label: 'Date' },
},
y: {
scale: scaleLinear,
nice: true,
grid: true,
axis: { label: 'Close (USD)' },
},
})The rolling average is an ordinary, visible data transform. The direct d3-array and d3-scale imports are application dependencies. Install those modules and their matching @types packages alongside TanStack Charts. Installation lists the exact packages, and Scales and D3 explains the ownership boundary.
TanStack Charts owns the parts that make a declarative chart reliable inside an application:
TanStack Charts keeps data preparation explicit and spatial algorithms outside the rendering runtime.
| Responsibility | Owner |
|---|---|
| Common group, bin, window, normalize, select, and row-stack transforms | TanStack's eager data-transform helpers |
| Scale choice, fixed semantic domains, interpolation, specialized statistics, and spatial algorithms | Your application using the granular D3 modules it needs |
| Fetching, cleaning, profiling, and exploratory analysis | Your data layer, server, or AI workflow |
| Mark-channel domain inference, responsive ranges, guide layout, scenes, rendering, and chart lifecycle | TanStack Charts |
| Page controls, queries, filters, persistence, memoization, and application state | Your application |
Prepared data can come from TanStack transforms, D3, SQL, a server, or ordinary TypeScript; marks consume it without requiring a special series container.
The normal path is intentionally short:
Every automatic behavior has an explicit escape hatch. The Guides cover those controls by task rather than repeating the API reference.
| Package | Use it for |
|---|---|
| @tanstack/charts | Definitions, marks, scenes, SVG, Canvas, export, and vanilla DOM |
| @tanstack/react-charts | React <Chart> |
| @tanstack/react-native-charts | Experimental React Native SVG <Chart> |
| @tanstack/preact-charts | Preact <Chart> |
| @tanstack/vue-charts | Vue <Chart> |
| @tanstack/solid-charts | Solid <Chart> |
| @tanstack/svelte-charts | Svelte <Chart> |
| @tanstack/angular-charts | Angular <tanstack-chart> |
| @tanstack/lit-charts | Lit <tanstack-chart> |
| @tanstack/alpine-charts | Alpine x-chart |
| @tanstack/octane-charts | Octane <Chart> |
All packages are ESM and tree-shakeable. Built-in marks and optional capabilities also have subpath exports when a library or design system needs tighter bundle boundaries.