TanStack
API Reference

Types

TanStack Charts is inference-first. A mark's source data and channel selectors flow through its definition into scales, axis formatters, host and adapter callbacks, focus callbacks, and selection callbacks. Normal application code should not cast chart definitions or supply adapter generics.

Browser applications can import types from the package root. Platform-neutral libraries can import the same definition, mark, scene, runtime, focus, and tooltip-model contracts from @tanstack/charts/types; DOM host and renderer types remain available from the root.

Values and channels

ts
type ChartValue = number | string | Date
type ChartKey = string | number

type ChannelAccessor<TDatum, TValue> = (
  datum: TDatum,
  index: number,
  data: readonly TDatum[],
) => TValue

type Channel<TDatum, TValue> =
  ChannelField<TDatum, TValue> | ChannelAccessor<TDatum, TValue>

type VisualChannel<TDatum, TValue> = TValue | ChannelAccessor<TDatum, TValue>

The corresponding public type names are Channel, ChannelAccessor, and VisualChannel.

A Channel accepts only datum keys whose declared values are compatible with the channel, or an accessor that derives a value from the row, index, and full readonly data array. A VisualChannel replaces the field-name form with a constant: it accepts either one constant value or an accessor.

ts
import { lineY } from '@tanstack/charts'

interface Row {
  date: Date
  value: number
  label: string
  series: 'actual' | 'forecast'
}

lineY(rows, {
  x: 'date', // Date
  y: 'value', // number
  z: 'series',
  stroke: (row) => (row.series === 'actual' ? '#2563eb' : '#60a5fa'),
})

ChannelField, ChannelOutput, OptionChannelOutput, WidenChartValue, and ChartAxisValue are exported for extension authors. Literal chart values widen to their semantic primitive so a literal row does not produce an unusably narrow scale or callback type.

Inference path

plaintext
source datum
  → mark channel outputs
  → ChartMark point and scale value types
  → ChartSpec axis requirements and definition datum/x/y unions
  → axis scale and formatter types
  → host and adapter callback types

Marks in one chart may have different datum types. The definition exposes their union. TypeScript narrowing is therefore required when a callback handles heterogeneous layers.

ChartMarkScaleX and ChartMarkScaleY also control the chart shape. A materialized scale value makes that axis required. never makes it optional and null-only, so positionless and one-dimensional charts do not carry phantom scale configuration.

Rect and custom interval marks can distinguish materialized scale values from interaction point values. The exported extractors are:

ChartMarkDatum, ChartSpecDatum, ChartSpecXValue, and ChartSpecYValue are available from the root entry point. The four ChartMarkPoint* and ChartMarkScale* extractors below come from the exceptional @tanstack/charts/mark/scale-values subpath.

TypeExtracts
ChartMarkDatum<TMark>Original datum
ChartMarkPointX<TMark>Interaction x value; exported from @tanstack/charts/mark/scale-values
ChartMarkPointY<TMark>Interaction y value; exported from @tanstack/charts/mark/scale-values
ChartMarkScaleX<TMark>All x values materialized for scale typing; exported from @tanstack/charts/mark/scale-values
ChartMarkScaleY<TMark>All y values materialized for scale typing; exported from @tanstack/charts/mark/scale-values
ChartSpecDatum<TSpec>Datum union across marks
ChartSpecXValue<TSpec>Interaction x union across marks
ChartSpecYValue<TSpec>Interaction y union across marks

ChartMarkX and ChartMarkY remain exported as deprecated aliases of the point extractors. New code should use the explicit names.

Stateful mark presentation uses ChartMarkStateContext as one object bag for the datum, index, data, point, focus, pointer, and matching helper. A ChartMarkStateSelector handles the common declarative cases, while callbacks can return any ChartMarkStateValue. ChartMarkStateStyle is the complete style vocabulary; ChartDotStateStyle, ChartBarStateStyle, ChartRectStateStyle, ChartLineStateStyle, ChartAreaStateStyle, and ChartTextStateStyle narrow it to properties each mark can render.

Definitions

TypePurpose
ChartSpecMarks plus conditionally required axes, guides, color, resources, and layout
StaticChartDefinitionA directly compilable spec with inferred datum and semantic x/y phantom types
DynamicChartDefinitionResponsive chart builder
ChartDefinitionStatic or dynamic union
ChartBuildContextCurrent size and build-time theme

The complete overloads and runtime rules are in Chart Definition API.

Marks and scenes

TypePurpose
ChartMarkPublic initialized-mark factory plus inferred point and scale types
MarkInitializeContextMark layer index
InitializedMarkStable ID, materialized channels, optional layout labels, and render function
MaterializedChannelValues contributed to an optional named scale
MarkRenderContextFinal chart bounds, scales, theme, color resolver, and layout
MarkSceneMark-owned scene nodes and optional interaction points
ChartSceneComplete renderer-neutral output
ChartPointTyped interaction target
ChartTickSemantic value, formatted label, and pixel position
ResolvedScaleFinal positional scale
ResolvedColorScaleFinal color scale

Scene geometry and interaction point fields are documented in Runtime and scene.

Scene-node types

SceneNode is the union of:

  • SceneGroup
  • SceneRule
  • ScenePolyline
  • SceneArea
  • SceneDot
  • SceneRect
  • SceneLabel

SceneStyle is shared presentation. ChartSize, ChartBounds, ChartMargin, ChartLayoutOptions, ChartTextMeasurer, ChartTextMeasureOptions, and ChartTextMetrics describe scene and text geometry.

See Scene nodes.

Scale, guide, color, and theme types

TypePurpose
ChartAxisOptionsRequired positional scale and optional guide behavior
ChartAxisGuideOptionsGuide behavior without the scale field
ChartAxisPresentationOptionsAxis line, ticks, tick labels, and title presentation
ChartAxisTickOptionsCandidate values, density, formatting, size, and padding
ChartAxisTickLabelOptionsOptional rotation and collision-aware thinning
ChartAxisTickLabelThinOptionsMinimum gap, end priority, and labels that must be kept
ChartAxisLabelOptionsAxis title text and explicit or measured offset
ChartScaleFactoryCreates a positional scale with a mark-inferred domain
ChartScaleInputFactory or configured positional scale instance
InferableScaleLikeDomain-configurable scale returned by a factory
ConfiguredScaleLikeCallable, copyable positional scale contract
ChartNumericScaleRadius mapper, configured instance, or inferred factory spec
ChartNumericScaleOptionsInferred or configured radius scale with optional nicening
ChartScaleCustom positional scale extension
ChartScaleResolveContextValues, responsive range, guide options, and hints
ChartScaleResolverFunction form of custom scale resolution
ChartColorOptionsFactory, configured/custom color scale, hints, and legend
ChartColorScaleFactoryCreates a color scale with a channel-inferred domain
ConfiguredColorScaleLikeCallable and copyable color scale contract
InferableColorScaleLikeDomain-configurable color scale returned by a factory
ChartColorScaleCustom color scale extension
ChartColorScaleContextObserved values, hints, and theme
ResolvedColorScaleResolved mapping and optional stepped legend boundaries
ResolvedColorScaleKindCategorical, continuous, quantile, quantize, or threshold
ChartColorLegendLegend layout and scene rendering
ChartColorLegendContextResolved colors, chart bounds, theme, and width
ChartThemeForeground, muted, grid, background, and palette
ChartLinearGradientNamed linear-gradient resource
ChartGradientStopGradient offset, color, and optional opacity
ChartCurveLine and y-area path generation

See Scales, guides, and color.

Host and runtime types

TypePurpose
ChartHostCommonOptionsAccessibility, sizing, callbacks, and SVG renderer options
ChartHostOptionsCommon options plus a chart definition
ChartHostSVG host update, getScene, and destroy
ChartRendererHostCommonOptionsRenderer-neutral common options plus required renderer
ChartRendererHostOptionsRenderer-neutral options plus a chart definition
ChartRendererHostRenderer-neutral update, getScene, and destroy
ChartRuntimeRepeated static or responsive scene rendering
ChartRenderContextContainer, live SVG, and scene reported after DOM render
ChartRendererRenderContextContainer, live renderer surface, and scene reported after render

See DOM host and Runtime and scene.

Focus and tooltip types

TypePurpose
ChartFocusStrategyPointer resolution, grouping, and keyboard ordering
ChartFocusPresetBuilt-in nearest and grouped axis focus names
ChartFocusModeFocus preset or custom strategy
ChartFocusStatePrimary, group, source, and pinned interaction state
ChartFocusSourcePointer, keyboard, programmatic, or restored source
ChartFocusFilterFocus-filtered mark matching configuration
ChartFocusMatchPrimary, group, key, x, y, or series matching
ChartSpatialIndexNearest-point query
ChartSpatialIndexFactoryBuilds an index from current scene points
ChartExtensionInputGeneric bare-token or { use, ...options } extension input
ChartTooltipInputTooltip extension token or configured extension options
ChartTooltipExtensionTokenEnvironment-neutral contract implemented by host tooltip extensions
ChartTooltipExtensionTooltip lifecycle implementation
ChartTooltipExtensionContextContainer, dismissal, and adapter-body bridge given to a tooltip
ChartTooltipExtensionInstanceTooltip update, paint, hide, containment, and destroy lifecycle
ChartTooltipPaintContextFocus, points, scene, surface, pointer, and pinned state
ChartTooltipOptionsNative tooltip content, ordering, anchoring, and pinning
ChartTooltipPortalInputPortal extension token or configured transport options
ChartTooltipPortalExtensionTokenEnvironment-neutral contract implemented by host portal extensions
ChartTooltipPortalExtensionTooltip transport lifecycle implementation
ChartTooltipPortalExtensionContextContainer, tooltip element, and reposition callback given to a portal
ChartTooltipPortalExtensionInstancePortal update, position, hide, and destroy lifecycle
ChartTooltipPortalOptionsReserved configuration object for portal extensions
ChartTooltipPortalPositionContextScene, surface, anchor, placement, and offset for viewport positioning
ChartTooltipItemOrdered channel, datum-field, or derived point row
ChartTooltipItemBaseShared label and point-text contract for object items
ChartTooltipChannelItemConfigured x, y, or group row
ChartTooltipDatumItemScalar datum-field row
ChartTooltipDerivedItemRow derived from the complete focused point
ChartTooltipSortGroup row ordering
ChartTooltipAnchorPreset, independent axis coordinates, or custom scene anchor
ChartTooltipAxisAnchorIndependent x and y anchor sources
ChartTooltipXAnchorPoint, pointer, value, group, or plot x source
ChartTooltipYAnchorPoint, pointer, value, group, or plot y source
ChartTooltipAnchorContextFocus, pointer, plot, surface, and resolved scales
ChartTooltipPlacementTooltip box placement around its anchor
ChartTooltipPositionScene-pixel x/y coordinate
ChartDefinitionOptionsFocus, tooltip, animation, keyboard, and spatial policy
DynamicChartConfigResponsive builder plus definition-owned behavior
ChartTooltipContentSafe title and row model for a native tooltip
ChartTooltipRowLabel, formatted value, and optional color swatch
ChartTooltipContentContextAxis labels and value formatters for content callbacks
ChartTooltipBodyContextFocused points, content, pinned state, and dismissal
ChartTooltipBodyTargetRenderer-adapter body mount element plus body context

See Focus and interaction.

Rendering types

TypePurpose
RenderChartOptionsRenderer-neutral accessible name, description, class, tab index, and ID prefix
RenderChartSvgOptionsSVG specialization of RenderChartOptions
ChartSurfaceRenderOptionsRender options plus optional animation
ChartSurfaceMounted element, painting, coordinates, focus, and cleanup
ChartRendererServer shell and browser-surface renderer contract
ChartSvgRendererScene-to-SVG string function
ChartAnimationOptionsDuration, easing, and reduced-motion policy

See Rendering and export.

Capability-specific types

Types tied to optional capabilities are documented with the API that owns their behavior:

  • @tanstack/charts/adapter: ChartAdapter, ChartAdapterLayout, and ChartAdapterLayoutOptions. See Adapter controller.
  • @tanstack/charts/canvas: CanvasChartRendererOptions, CanvasChartRenderer, CanvasChartSurface, CanvasChartHostOptions, and CanvasChartHost. See Canvas renderer.
  • @tanstack/charts/export: SerializeChartSvgOptions and RenderChartPngOptions. See SVG serialization and browser image export.
  • @tanstack/charts/geo: GeoProjectionContext, GeoProjectionDescriptor, GeoProjectionInput, and GeoShapeOptions. See Geo shape.
  • @tanstack/charts/polar: PolarOptions, PolarMark, PolarGuide, PolarGuideScene, PolarAngleOptions, PolarRadiusOptions, PolarResolvedScale, PolarLayoutContext, PolarLength, PolarGuideLabelContext, PolarGuideLabelOption, RadialArcOptions, RadialLineOptions, RadialAreaOptions, RadialDotOptions, RadialTextOptions, RadialRuleOptions, RadialGridOptions, and AngleGridOptions. See Polar marks.

Mark option types

Every built-in mark exports its options type from the root and its granular subpath:

  • LineYOptions, AreaYOptions, AreaXOptions, AreaXCurve
  • BarYOptions, BarXOptions
  • DotOptions, HexagonOptions
  • RectOptions, CellOptions
  • RuleXOptions, RuleYOptions
  • LinkOptions, ArrowOptions, VectorOptions, VectorAnchor
  • TickXOptions, TickYOptions
  • TextOptions, TextAnchor
  • FrameOptions
  • FacetOptions, FacetAxes
  • ColorLegendOptions, ColorGradientLegendOptions

Their public fields and defaults are owned by the mark reference and legend reference.

Correcting a type error

When a normal chart requires as, first check:

  1. Is the row interface accurate, including nullable values?
  2. Is the selected field compatible with the mark channel?
  3. Does the configured scale domain accept the inferred semantic value?
  4. Does the definition capture values with their exact application types?
  5. Are mixed mark datum or value unions being narrowed honestly?
  6. Is a custom mark declaring its datum and point values at createMark?

Use an assertion only at a genuinely unchecked external boundary. Do not cast the definition or framework props to bypass a mismatch.