Skip to content

Pie chart ​

Slices of a whole. Good for two to five shares that add up to a total.

The smallest code that works. change the code, then press Run

In your framework

import { Chart } from 'nervure/react';

const spec = {
  type: 'pie',
  inner: 0,
  data: [
    { name: 'Juice', value: 86 },
    { name: 'Tea', value: 10 },
    { name: 'Cheese', value: 59 },
    { name: 'Soup', value: 8 },
    { name: 'Dates', value: 42 },
  ],
};

export default function Example() {
  return <Chart spec={spec} style={{ height: 340 }} />;
}

Or import this chart alone: what each import weighs.

Options

Beside the fields shared by every chart (title, format, heading, export…), type pie takes:

interface PieSpec extends Base {
  type: 'pie';
  data: { name: string; value: number; color?: string }[];
  inner?: number;
  outer?: number;
  labels?: boolean;
  /** Outside label of a slice. */ label?: (name: string, value: number, percent: number) => string;
  /** Text in the hole of a donut. */ center?: string;
}

Style it

  • Colours: theme.palette, chart.setColor(name, colour), or --nervure-palette in your CSS. More
  • Marks: [data-series="name"], parts: [data-part="axes"], legend, series. What you change is kept in exports.
  • Movement: animation: false draws at once. More
  • Files: chart.download('png'), svg, csv. More

Close to it