TanStack
API Reference

Lit Chart

ts
import { Chart, defineChartElement } from '@tanstack/lit-charts'

defineChartElement() registers Chart as tanstack-chart. Pass the complete chart value through the element's options property, not HTML attributes. Replace the definition identity when captured application values change. The definition also owns focus, tooltip, animation, keyboard policy, focus distance, and spatial indexing.

options

OptionTypeDefaultMeaning
definitionChartDefinitionRequiredFramework-neutral chart definition
ariaLabelstringRequiredAccessible chart name
ariaDescriptionstringNoneOptional accessible description
heightnumber320 without a ratioFixed CSS and scene height
aspectRationumberNonePositive width-to-height ratio when height is absent
widthnumberResponsiveFixed CSS and scene width
initialWidthnumber640Initial width before responsive measurement
tabIndexnumber0Surface tab index; keyboard: false forces -1
idPrefixstringGeneratedPrefix for renderer-owned document IDs
renderSvgChartSvgRenderer<TDatum, TXValue, TYValue>renderChartSvgScene-to-SVG renderer
measureTextChartTextMeasurerHost measurerGuide text measurement
onFocusChange(point: ChartPoint | null) => voidNonePrimary focus callback
onFocusGroupChange(points: readonly ChartPoint[]) => voidNoneGrouped focus callback
onSelect(point: ChartPoint | null) => voidNonePointer or keyboard activation callback
onRender(context: ChartRenderContext) => voidNoneLive SVG, container, and scene after rendering
renderTooltipBody(context: ChartTooltipBodyRenderContext) => unknownNoneComposes Lit content inside the native tooltip body
classstringNoneExtra class on the inner .ts-chart-host
stylestringNoneInner host declarations applied after adapter sizing
classNamestringNoneExtra class on the rendered SVG surface
ts
const options = {
  definition,
  ariaLabel: 'Revenue',
  renderTooltipBody: ({ points, defaultBody, pinned, dismiss }) => html`
    ${defaultBody}
    <series-detail .points=${points}></series-detail>
    ${pinned ? html`<button @click=${dismiss}>Close</button>` : nothing}
  `,
}

The context also exposes resolved content. defaultBody is a TemplateResult. Ordering, anchoring, placement, portaling, and pinning remain in the definition.

Registration and exported types

defineChartElement(tagName = 'tanstack-chart') is idempotent for an already registered tag. Importing Chart directly supports explicit custom-element registration.

ChartCommonProps contains common host and presentation props. ChartProps adds the definition. ChartPresentationProps contains class and style. ChartTooltipBodyRenderContext describes composed tooltip content. The package also re-exports ChartDefinition and ChartPoint.

See the Lit adapter for lifecycle and browser behavior, Focus and interaction for callback semantics, and Rendering and export for custom SVG renderers.