Chartist

Search

Find a guide, an API entry or an example.

Try

Legend beside a donut

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
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' })] }
});
Live