# Quick start

From an empty React app to a chart on screen, in three steps.

The components take rows you already have, so there is nothing to fetch or configure.

## 1. Install

```bash
npm install em-kit
pnpm add em-kit   # or, with pnpm
yarn add em-kit   # or, with yarn
bun add em-kit   # or, with bun
```

The only peer dependencies are `react` and `react-dom`, version 19.1.1 or later. Chart.js and the other runtime dependencies install with the package, and there is no stylesheet to import.

## 2. Add the provider

Wrap your app in `ChartsProvider` once. Charts read their theme, language and time zone from it: see [Theming](/docs/theming.md) and [Localisation](/docs/localisation.md). `RevenueChart` is the file you add in step 3.

```tsx title="App.tsx"
import { ChartsProvider } from 'em-kit';
import { RevenueChart } from './RevenueChart';

export default function App() {
  return (
    <ChartsProvider>
      <RevenueChart />
    </ChartsProvider>
  );
}
```

The provider loads the Inter font from Google Fonts; to serve it yourself or turn it off, see [fonts](/docs/troubleshooting.md#chart-text-is-in-a-serif-or-system-font).

### In the Next.js App Router

Next.js renders a file on the server unless it starts with `'use client'`, and the components use React context. Put the provider in a client file that pins the locale, so the server and the browser format numbers alike, and render it from the root layout.

```tsx title="app/ClientProvider.tsx"
'use client';

import type { ReactNode } from 'react';
import { ChartsProvider } from 'em-kit';

// Render this from app/layout.tsx. Files that render charts start with
// 'use client' too. The fixed locale makes the server format numbers as the
// browser will; use the reader's locale from the request if you have it.
export function ClientProvider({ children }: { children: ReactNode }) {
  return <ChartsProvider theme={{ formatter: { locale: 'en-US' } }}>{children}</ChartsProvider>;
}
```

```tsx title="app/layout.tsx"
import type { ReactNode } from 'react';
import { ClientProvider } from './ClientProvider';

export default function RootLayout({ children }: { children: ReactNode }) {
  return (
    <html lang="en">
      <body>
        <ClientProvider>{children}</ClientProvider>
      </body>
    </html>
  );
}
```

Start `RevenueChart.tsx` from step 3 with `'use client';` as well, and render it from a page.

```tsx title="app/page.tsx"
import { RevenueChart } from '../RevenueChart';

export default function Page() {
  return <RevenueChart />;
}
```

## 3. Render a chart

Describe each field once, then pass your rows to `results`. The chart fills its parent, so give the parent a height, and a width it can fill.

```tsx title="RevenueChart.tsx"
import { BarChart, dimension, measure, results } from 'em-kit';

const region = dimension({ name: 'region', title: 'Region' });
const revenue = measure({ name: 'revenue', title: 'Revenue' });

// One row per bar. Each key is the `name` of a field above.
const rows = [
  { region: 'North America', revenue: 48200 },
  { region: 'Europe', revenue: 39500 },
  { region: 'Asia Pacific', revenue: 27800 },
  { region: 'Latin America', revenue: 12100 },
];

export function RevenueChart() {
  return (
    <div style={{ height: 360 }}>
      <BarChart
        title="Revenue by region"
        dimension={region}
        measures={[revenue]}
        results={results(rows)}
      />
    </div>
  );
}
```

Result: a card titled “Revenue by region” with four bars, labelled 48,200, 39,500, 27,800 and 12,100.

The numbers are formatted for your browser’s locale, and the menu in the card’s corner exports CSV, Excel and PNG.

## Next steps

- [Describing your data](/docs/describing-your-data.md): dimensions, measures and field options, such as `currency: 'USD'` for $48,200
- [Time series](/docs/time-series.md): dates on the axis, the timestamp format and missing periods
- [Components](/docs/components.md): every chart, with examples and props
- [Troubleshooting](/docs/troubleshooting.md): what to check if the chart does not appear or looks wrong
