# Charts

Plot data with TanStack Charts and render it in React with Ghost UI.

## How the chart works

TanStack Charts builds the chart from data, scales, and marks such as lines or bars. Ghost’s Chart renders it in React and adds styles for focus, tooltips, and labels.

See the [Chart component](/components/chart) for examples of different chart types.

## Render your first chart

Install [Ghost UI](/docs/installation#package), then add the chart packages.

```bash
npm install @tanstack/charts@1.1.0 @tanstack/react-charts@1.1.0
```

Load these styles once in your app entry point or root layout.

```tsx
import "@collectivecreation/ghost-ui/styles.css";
import "@collectivecreation/ghost-ui/charts.css";
```

Render SuccessChart to see task success rise from 61% to 71%.

```tsx
import { defineChart, lineY } from "@tanstack/charts";
import { scaleLinear } from "@tanstack/charts/scales/linear";
import { tooltip } from "@tanstack/charts/tooltip";
import { Chart } from "@collectivecreation/ghost-ui/charts";
const rows = [{ week: 1, success: 61 }, { week: 2, success: 71 }];
const definition = defineChart({
  marks: [lineY(rows, { x: "week", y: "success", points: true })],
  scales: {
    x: { scale: scaleLinear().domain([1, 2]), axis: { label: "Week" } },
    y: { scale: scaleLinear().domain([0, 100]), axis: { label: "Task success (%)" } },
  },
}, { tooltip: { use: tooltip } });
export function SuccessChart() {
  return <Chart definition={definition} ariaLabel="Weekly task success: 61 then 71 percent" />;
}

```

lineY draws a line from the rows. The x and y keys tell it which fields to plot. Use scales to set the axis ranges, and label the axes with units.

## Data and interaction

Fetch and prepare the data in your app. Decide how to handle missing values, timezones, loading, and errors. Pass a new definition when the data changes so the chart can update.

Register tooltip in the definition to show values on inspection. Give the chart a useful accessible name. Provide a table or text summary when readers need exact values.

See [Chart models and extensions](/libraries/chart-models) for custom rendering and export. Use the [TanStack Charts reference](https://tanstack.com/charts/latest/docs/overview) for marks, scales, and plugins. Match its examples to the version you installed.

## Troubleshooting

- The chart is blank. Check for rows, matching field names, an axis range that includes them, and a container with usable dimensions.

- The tooltip is missing. Register the tooltip plugin.

- The chart still shows old values. Pass a new definition instead of mutating its data in place.
