<div align="center">
  <picture>
    <source
      media="(prefers-color-scheme: dark)"
      srcset="https://tanstack.com/api/readme/charts.png?framework=react&theme=dark"
    />
    <source
      media="(prefers-color-scheme: light)"
      srcset="https://tanstack.com/api/readme/charts.png?framework=react"
    />
    <img
      src="https://tanstack.com/api/readme/charts.png?framework=react"
      alt="TanStack React Charts"
      width="900"
    />
  </picture>
</div>

# `@tanstack/react-charts`

This compatibility package remains supported for existing applications. New
applications use the React adapter from `@tanstack/charts/react`.

Install Charts and the React peers:

```sh
pnpm add @tanstack/charts react react-dom
pnpm add -D @types/react @types/react-dom
```

Add granular `d3-*` modules and their matching type packages only when the
chart needs scale or algorithm semantics outside the compact set.

```tsx
import { defineChart } from '@tanstack/charts'
import { tooltip } from '@tanstack/charts/tooltip'
import { Chart } from '@tanstack/charts/react'

const interactiveDefinition = defineChart(definition, {
  svgAnimation: true,
  tooltip,
})

;<Chart
  definition={interactiveDefinition}
  aspectRatio={16 / 9}
  initialWidth={640}
  ariaLabel="Revenue by month"
  ariaDescription="Monthly revenue for the current fiscal year."
  onFocusChange={setFocusedPoint}
  onSelect={setSelectedPoint}
/>
```

The base `Chart` renders the core native tooltip without including React
tooltip-body composition. Import the drop-in component from `/tooltip` only
when passing `renderTooltipBody`:

```tsx
import { Chart } from '@tanstack/charts/react/tooltip'

;<Chart
  definition={interactiveDefinition}
  ariaLabel="Revenue by month"
  renderTooltipBody={({ defaultBody, pinned, dismiss }) => (
    <>
      {defaultBody}
      {pinned ? <button onClick={dismiss}>Close</button> : null}
    </>
  )}
/>
```

Existing `renderTooltipBody` users should move their component import from
`@tanstack/charts/react` to `@tanstack/charts/react/tooltip`. That entry also
exports `CanvasChart` and `RendererChart` for the same opt-in with those
renderers.

Switch only the import to opt into Canvas:

```tsx
import { Chart } from '@tanstack/charts/react/canvas'
```

The default entry remains SVG-based. `@tanstack/charts/react/core` accepts an
explicit `renderer` for application-owned surfaces, and neither optional path
pulls Canvas into the default bundle.

The adapter server-renders the complete shared SVG. On the client, React owns
only the outer host; the framework-neutral chart host owns measurement,
reconciliation, animation, and interaction. Reuse the definition while its
captured values are unchanged; a new definition updates the mounted surface
without replacing it.

The definition drives all prop inference. Focus, group, selection, and render
callbacks infer the original datum. Do not add adapter generics or cast adapter
props; fix the definition, channel, or scale that TypeScript rejects.

Use `height` for a fixed-height chart or `aspectRatio` for proportional
container sizing.

Read the installed `@tanstack/charts/llms.txt` documentation map, the published
[React Quick Start](https://tanstack.com/charts/latest/docs/framework/react/quick-start),
or the
[React Adapter guide](https://tanstack.com/charts/latest/docs/framework/react/adapter).

Licensed under [MIT](./LICENSE). Project credits are in the repository
[`ACKNOWLEDGEMENTS.md`](https://github.com/TanStack/charts/blob/main/ACKNOWLEDGEMENTS.md).
