# Legend beside a donut (Chartist example)

> Where visitors came from as a donut with each share on its slice, and the sources named in a legend on the right.

`src/main.ts`:

```ts
import 'chartist/styles.css';
import '@chartist-js/essentials/styles.css';
import { pieChart } from 'chartist';
import { legend } from '@chartist-js/essentials';

const data = {
  labels: ['Search', 'Direct', 'Social', 'Email'],
  series: [48, 27, 15, 10]
};

// The slices show their share; the legend on the right names them.
pieChart('#chart', data, {
  donut: true,
  labelTransform: (_, index) => `${data.series[index]}%`,
  layers: { above: [legend({ side: 'right' })] }
});
```

`index.html`:

```html
<!doctype html>
<html>
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <script type="module" src="/src/main.ts"></script>
  </head>
  <body>
    <div id="chart" style="height: 50vh"></div>
  </body>
</html>
```
