# Pie and donut

> Show a handful of shares of one whole with a pie or donut, then add a center label, group small slices, label with leader lines or sweep a half circle.

A pie chart shows how one whole divides among a few categories, and the reader judges each share by the angle of its slice. It works when there are about five categories or fewer and one or two shares are the point.

Use a [bar chart](/docs/comparison/bar/) once you have more than six or seven categories, or when the reader must compare close values, because length is easier to judge than angle. Use a [waffle chart](/docs/part-to-whole/waffle/) when the audience should be able to count units. A donut is a pie with a hole, and the same rules apply.

## A basic pie

Set `mark` to `"arc"`, put the number on `theta` and the category on `color`. No `x` or `y` channel is needed. OpenChart labels slices directly with leader lines instead of relying on a legend. Here the small browsers are folded into one "Others" slice in the data before it reaches the chart.

```json
{
  "mark": "arc",
  "data": [
    {
      "browser": "Chrome",
      "share": 63.6
    },
    {
      "browser": "Safari",
      "share": 19.8
    },
    {
      "browser": "Edge",
      "share": 5.3
    },
    {
      "browser": "Others",
      "share": 11.3
    }
  ],
  "encoding": {
    "theta": {
      "field": "share",
      "type": "quantitative"
    },
    "color": {
      "field": "browser",
      "type": "nominal"
    }
  },
  "chrome": {
    "title": "Chrome has nearly two-thirds of the browser market",
    "subtitle": "Global desktop and mobile browser share, January 2024 (%)"
  }
}
```

## A donut

Pass the mark as an object and set `innerRadius` above zero to make a donut. The hole is always 60% of the outer radius, so the value only turns it on. The spec is otherwise the same, and the hole leaves room for a headline number.

```json
{
  "mark": {
    "type": "arc",
    "innerRadius": 0.6
  },
  "data": [
    {
      "category": "Healthcare",
      "spending": 24
    },
    {
      "category": "Social Security",
      "spending": 21
    },
    {
      "category": "Defense",
      "spending": 13
    },
    {
      "category": "Net Interest",
      "spending": 13
    },
    {
      "category": "All Other",
      "spending": 29
    }
  ],
  "encoding": {
    "theta": {
      "field": "spending",
      "type": "quantitative"
    },
    "color": {
      "field": "category",
      "type": "nominal"
    }
  },
  "chrome": {
    "title": "Healthcare and Social Security take nearly half the budget",
    "subtitle": "Share of $6.9 trillion in federal spending, fiscal year 2024"
  }
}
```

## A center label

`centerLabel` on the arc mark prints a headline in the hole: a string for one line, or an object with `text` and `subtitle`. The label is decoration, since the number is already in the slices, and it only applies when the mark has an inner radius.

```json
{
  "mark": {
    "type": "arc",
    "innerRadius": 0.6,
    "centerLabel": {
      "text": "$6.9T",
      "subtitle": "total outlays"
    }
  },
  "data": [
    {
      "category": "Healthcare",
      "spending": 24
    },
    {
      "category": "Social Security",
      "spending": 21
    },
    {
      "category": "Defense",
      "spending": 13
    },
    {
      "category": "Net Interest",
      "spending": 13
    },
    {
      "category": "All Other",
      "spending": 29
    }
  ],
  "encoding": {
    "theta": {
      "field": "spending",
      "type": "quantitative"
    },
    "color": {
      "field": "category",
      "type": "nominal"
    }
  },
  "chrome": {
    "title": "The hole can carry the total",
    "subtitle": "Share of $6.9 trillion in federal spending, fiscal year 2024"
  }
}
```

## Small slices

Slices under about 3% of the total are grouped into a single "Other" slice, so a long tail of tiny values does not crowd the chart. This data has twelve countries, and the smallest are folded together.

```json
{
  "mark": "arc",
  "data": [
    {
      "country": "China",
      "emissions": 12600
    },
    {
      "country": "United States",
      "emissions": 4500
    },
    {
      "country": "India",
      "emissions": 3000
    },
    {
      "country": "Russia",
      "emissions": 1900
    },
    {
      "country": "Japan",
      "emissions": 1000
    },
    {
      "country": "Germany",
      "emissions": 620
    },
    {
      "country": "South Korea",
      "emissions": 590
    },
    {
      "country": "Iran",
      "emissions": 580
    },
    {
      "country": "Canada",
      "emissions": 530
    },
    {
      "country": "Indonesia",
      "emissions": 490
    },
    {
      "country": "Saudi Arabia",
      "emissions": 480
    },
    {
      "country": "Turkey",
      "emissions": 420
    }
  ],
  "encoding": {
    "theta": {
      "field": "emissions",
      "type": "quantitative"
    },
    "color": {
      "field": "country",
      "type": "nominal"
    }
  },
  "chrome": {
    "title": "China and the US emit 64% of the CO₂ among these 12 countries",
    "subtitle": "Annual CO₂ emissions, million tonnes, 2024. Slices under about 3% are grouped into \"Other\"."
  }
}
```

## Leader-line labels

Leader lines are the default, so the spec sets nothing for them. They let long vendor names sit clear of the arcs, which matters on a donut with several slices of different sizes.

```json
{
  "mark": {
    "type": "arc",
    "innerRadius": 0.6
  },
  "data": [
    {
      "brand": "Apple",
      "share": 23
    },
    {
      "brand": "Samsung",
      "share": 16
    },
    {
      "brand": "Xiaomi",
      "share": 14
    },
    {
      "brand": "Transsion",
      "share": 9
    },
    {
      "brand": "vivo",
      "share": 8.5
    },
    {
      "brand": "OPPO",
      "share": 8
    },
    {
      "brand": "Others",
      "share": 21.5
    }
  ],
  "encoding": {
    "theta": {
      "field": "share",
      "type": "quantitative"
    },
    "color": {
      "field": "brand",
      "type": "nominal"
    }
  },
  "chrome": {
    "title": "Apple had the largest smartphone share in Q4 2024",
    "subtitle": "Global smartphone market share by vendor, Q4 2024 (%)"
  }
}
```

## A half donut

`startAngle` and `endAngle` restrict the arc to a partial sweep, in radians. Angles follow the d3 convention: 0 is straight up and they increase clockwise. `-Math.PI / 2` to `Math.PI / 2` gives a half circle, a common shape for showing control of a chamber.

```json
{
  "mark": {
    "type": "arc",
    "innerRadius": 0.6,
    "startAngle": -1.5707963267948966,
    "endAngle": 1.5707963267948966
  },
  "data": [
    {
      "party": "Democratic",
      "seats": 213
    },
    {
      "party": "Republican",
      "seats": 222
    }
  ],
  "encoding": {
    "theta": {
      "field": "seats",
      "type": "quantitative"
    },
    "color": {
      "field": "party",
      "type": "nominal",
      "scale": {
        "domain": [
          "Democratic",
          "Republican"
        ],
        "range": [
          "#1b7fa3",
          "#c44e52"
        ]
      }
    }
  },
  "chrome": {
    "title": "A half donut of chamber control",
    "subtitle": "435 House seats drawn as a 180-degree arc with startAngle and endAngle."
  }
}
```

## Fields that matter

| Field | What it does |
| --- | --- |
| `mark` | `"arc"` for a pie, or an object with `innerRadius` for a donut. |
| `mark.innerRadius` | Any value above zero makes a donut. The hole is always 60% of the outer radius, so the value only turns it on. |
| `mark.centerLabel` | A string or `{ text, subtitle }` printed in the donut hole. |
| `mark.startAngle`, `mark.endAngle` | Restrict the arc to a partial sweep, in radians. |
| `encoding.theta` | The quantitative value that sets each slice's angle. |
| `encoding.color` | The category of each slice. |
| `encoding.color.scale` | `domain` and `range` pin categories to colors. |

## Related

- [Waffle](/docs/part-to-whole/waffle/) shows shares as countable squares.
- [Parliament](/docs/part-to-whole/parliament/) shows seats in a hemicycle.
- [Stacked 100%](/docs/part-to-whole/stacked-100/) compares shares across several wholes.
- [Bar](/docs/comparison/bar/) ranks categories when there are too many for a pie.
- [Marks reference](/docs/spec/marks/) lists the channels and options each mark type takes.
