Skip to content
OpenChart

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 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 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.

Chrome 63.6%Safari 19.8%Others 11.3%Edge 5.3%Chrome has nearly two-thirds of the browsermarketGlobal desktop and mobile browser share, January 2024 (%)Chrome 63.6%Safari 19.8%Others 11.3%Edge 5.3%Chrome has nearly two-thirds of the browsermarketGlobal desktop and mobile browser share, January 2024 (%)
Browser share. Source: StatCounter Global Stats.
{
  "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 (%)"
  }
}
import { Chart } from "@opendata-ai/openchart-react";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

const spec: ChartSpec = {
  "mark": "arc",
  "data": [/* 4 rows, as in the Spec tab; Copy includes them */],
  "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 (%)"
  }
};

export function Example() {
  return <Chart spec={spec} />;
}
<script setup lang="ts">
import { Chart } from "@opendata-ai/openchart-vue";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

const spec: ChartSpec = {
  "mark": "arc",
  "data": [/* 4 rows, as in the Spec tab; Copy includes them */],
  "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 (%)"
  }
};
</script>

<template>
  <Chart :spec="spec" />
</template>
<script lang="ts">
import { Chart } from "@opendata-ai/openchart-svelte";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

const spec: ChartSpec = {
  "mark": "arc",
  "data": [/* 4 rows, as in the Spec tab; Copy includes them */],
  "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 (%)"
  }
};
</script>

<Chart {spec} />
import { createChart } from "@opendata-ai/openchart-vanilla";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

const spec: ChartSpec = {
  "mark": "arc",
  "data": [/* 4 rows, as in the Spec tab; Copy includes them */],
  "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 (%)"
  }
};

const container = document.getElementById("chart");
if (!container) throw new Error('Add <div id="chart"></div> to the page first.');
createChart(container, spec);

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.

All Other 29%Healthcare 24%Social Security 21%Defense 13%Net Interest 13%Healthcare and Social Security take nearlyhalf the budgetShare of $6.9 trillion in federal spending, fiscal year 2024All Other 29%Healthcare 24%Social Security 21%Defense 13%Net Interest 13%Healthcare and Social Security take nearlyhalf the budgetShare of $6.9 trillion in federal spending, fiscal year 2024
Federal spending by category. Source: Congressional Budget Office.
{
  "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"
  }
}
import { Chart } from "@opendata-ai/openchart-react";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

const spec: ChartSpec = {
  "mark": {
    "type": "arc",
    "innerRadius": 0.6
  },
  "data": [/* 5 rows, as in the Spec tab; Copy includes them */],
  "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"
  }
};

export function Example() {
  return <Chart spec={spec} />;
}
<script setup lang="ts">
import { Chart } from "@opendata-ai/openchart-vue";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

const spec: ChartSpec = {
  "mark": {
    "type": "arc",
    "innerRadius": 0.6
  },
  "data": [/* 5 rows, as in the Spec tab; Copy includes them */],
  "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"
  }
};
</script>

<template>
  <Chart :spec="spec" />
</template>
<script lang="ts">
import { Chart } from "@opendata-ai/openchart-svelte";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

const spec: ChartSpec = {
  "mark": {
    "type": "arc",
    "innerRadius": 0.6
  },
  "data": [/* 5 rows, as in the Spec tab; Copy includes them */],
  "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"
  }
};
</script>

<Chart {spec} />
import { createChart } from "@opendata-ai/openchart-vanilla";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

const spec: ChartSpec = {
  "mark": {
    "type": "arc",
    "innerRadius": 0.6
  },
  "data": [/* 5 rows, as in the Spec tab; Copy includes them */],
  "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"
  }
};

const container = document.getElementById("chart");
if (!container) throw new Error('Add <div id="chart"></div> to the page first.');
createChart(container, spec);

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.

All Other 29%Healthcare 24%Social Security 21%Defense 13%Net Interest 13%The hole can carry the totalShare of $6.9 trillion in federal spending, fiscal year 2024All Other 29%Healthcare 24%Social Security 21%Defense 13%Net Interest 13%The hole can carry the totalShare of $6.9 trillion in federal spending, fiscal year 2024
Federal spending with a center label. Source: Congressional Budget Office.
{
  "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"
  }
}
import { Chart } from "@opendata-ai/openchart-react";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

const spec: ChartSpec = {
  "mark": {
    "type": "arc",
    "innerRadius": 0.6,
    "centerLabel": {
      "text": "$6.9T",
      "subtitle": "total outlays"
    }
  },
  "data": [/* 5 rows, as in the Spec tab; Copy includes them */],
  "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"
  }
};

export function Example() {
  return <Chart spec={spec} />;
}
<script setup lang="ts">
import { Chart } from "@opendata-ai/openchart-vue";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

const spec: ChartSpec = {
  "mark": {
    "type": "arc",
    "innerRadius": 0.6,
    "centerLabel": {
      "text": "$6.9T",
      "subtitle": "total outlays"
    }
  },
  "data": [/* 5 rows, as in the Spec tab; Copy includes them */],
  "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"
  }
};
</script>

<template>
  <Chart :spec="spec" />
</template>
<script lang="ts">
import { Chart } from "@opendata-ai/openchart-svelte";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

const spec: ChartSpec = {
  "mark": {
    "type": "arc",
    "innerRadius": 0.6,
    "centerLabel": {
      "text": "$6.9T",
      "subtitle": "total outlays"
    }
  },
  "data": [/* 5 rows, as in the Spec tab; Copy includes them */],
  "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"
  }
};
</script>

<Chart {spec} />
import { createChart } from "@opendata-ai/openchart-vanilla";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

const spec: ChartSpec = {
  "mark": {
    "type": "arc",
    "innerRadius": 0.6,
    "centerLabel": {
      "text": "$6.9T",
      "subtitle": "total outlays"
    }
  },
  "data": [/* 5 rows, as in the Spec tab; Copy includes them */],
  "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"
  }
};

const container = document.getElementById("chart");
if (!container) throw new Error('Add <div id="chart"></div> to the page first.');
createChart(container, spec);

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.

China 47.2%United States 16.8%India 11.2%Russia 7.1%Japan 3.7%Other 13.9%China and the US emit 64% of the CO₂ amongthese 12 countriesAnnual CO₂ emissions, million tonnes, 2024. Slices under about 3% are grouped into"Other".China 47.2%United States 16.8%India 11.2%Russia 7.1%Japan 3.7%Other 13.9%China and the US emit 64% of the CO₂ amongthese 12 countriesAnnual CO₂ emissions, million tonnes, 2024. Slices under about 3% are grouped into"Other".
CO2 emissions by country. Source: Global Carbon Project.
{
  "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\"."
  }
}
import { Chart } from "@opendata-ai/openchart-react";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

const data = [/* 12 rows, as in the Spec tab; Copy includes them */];

const spec: ChartSpec = {
  data,
  "mark": "arc",
  "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\"."
  }
};

export function Example() {
  return <Chart spec={spec} />;
}
<script setup lang="ts">
import { Chart } from "@opendata-ai/openchart-vue";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

const data = [/* 12 rows, as in the Spec tab; Copy includes them */];

const spec: ChartSpec = {
  data,
  "mark": "arc",
  "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\"."
  }
};
</script>

<template>
  <Chart :spec="spec" />
</template>
<script lang="ts">
import { Chart } from "@opendata-ai/openchart-svelte";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

const data = [/* 12 rows, as in the Spec tab; Copy includes them */];

const spec: ChartSpec = {
  data,
  "mark": "arc",
  "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\"."
  }
};
</script>

<Chart {spec} />
import { createChart } from "@opendata-ai/openchart-vanilla";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

const data = [/* 12 rows, as in the Spec tab; Copy includes them */];

const spec: ChartSpec = {
  data,
  "mark": "arc",
  "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\"."
  }
};

const container = document.getElementById("chart");
if (!container) throw new Error('Add <div id="chart"></div> to the page first.');
createChart(container, spec);

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.

Apple 23%Others 21.5%Samsung 16%Xiaomi 14%Transsion 9%vivo 8.5%OPPO 8%Apple had the largest smartphone share in Q42024Global smartphone market share by vendor, Q4 2024 (%)Apple 23%Others 21.5%Samsung 16%Xiaomi 14%Transsion 9%vivo 8.5%OPPO 8%Apple had the largest smartphone share in Q42024Global smartphone market share by vendor, Q4 2024 (%)
Smartphone market share by vendor. Source: IDC Worldwide Quarterly Mobile Phone Tracker.
{
  "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 (%)"
  }
}
import { Chart } from "@opendata-ai/openchart-react";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

const data = [/* 7 rows, as in the Spec tab; Copy includes them */];

const spec: ChartSpec = {
  data,
  "mark": {
    "type": "arc",
    "innerRadius": 0.6
  },
  "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 (%)"
  }
};

export function Example() {
  return <Chart spec={spec} />;
}
<script setup lang="ts">
import { Chart } from "@opendata-ai/openchart-vue";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

const data = [/* 7 rows, as in the Spec tab; Copy includes them */];

const spec: ChartSpec = {
  data,
  "mark": {
    "type": "arc",
    "innerRadius": 0.6
  },
  "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 (%)"
  }
};
</script>

<template>
  <Chart :spec="spec" />
</template>
<script lang="ts">
import { Chart } from "@opendata-ai/openchart-svelte";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

const data = [/* 7 rows, as in the Spec tab; Copy includes them */];

const spec: ChartSpec = {
  data,
  "mark": {
    "type": "arc",
    "innerRadius": 0.6
  },
  "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 (%)"
  }
};
</script>

<Chart {spec} />
import { createChart } from "@opendata-ai/openchart-vanilla";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

const data = [/* 7 rows, as in the Spec tab; Copy includes them */];

const spec: ChartSpec = {
  data,
  "mark": {
    "type": "arc",
    "innerRadius": 0.6
  },
  "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 (%)"
  }
};

const container = document.getElementById("chart");
if (!container) throw new Error('Add <div id="chart"></div> to the page first.');
createChart(container, spec);

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.

Republican 51%Democratic 49%A half donut of chamber control435 House seats drawn as a 180-degree arc with startAngle and endAngle.Republican 51%Democratic 49%A half donut of chamber control435 House seats drawn as a 180-degree arc with startAngle and endAngle.
House seats as a half donut. Source: Illustrative data.
{
  "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."
  }
}
import { Chart } from "@opendata-ai/openchart-react";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

const spec: ChartSpec = {
  "mark": {
    "type": "arc",
    "innerRadius": 0.6,
    "startAngle": -1.5707963267948966,
    "endAngle": 1.5707963267948966
  },
  "data": [/* 2 rows, as in the Spec tab; Copy includes them */],
  "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."
  }
};

export function Example() {
  return <Chart spec={spec} />;
}
<script setup lang="ts">
import { Chart } from "@opendata-ai/openchart-vue";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

const spec: ChartSpec = {
  "mark": {
    "type": "arc",
    "innerRadius": 0.6,
    "startAngle": -1.5707963267948966,
    "endAngle": 1.5707963267948966
  },
  "data": [/* 2 rows, as in the Spec tab; Copy includes them */],
  "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."
  }
};
</script>

<template>
  <Chart :spec="spec" />
</template>
<script lang="ts">
import { Chart } from "@opendata-ai/openchart-svelte";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

const spec: ChartSpec = {
  "mark": {
    "type": "arc",
    "innerRadius": 0.6,
    "startAngle": -1.5707963267948966,
    "endAngle": 1.5707963267948966
  },
  "data": [/* 2 rows, as in the Spec tab; Copy includes them */],
  "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."
  }
};
</script>

<Chart {spec} />
import { createChart } from "@opendata-ai/openchart-vanilla";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

const spec: ChartSpec = {
  "mark": {
    "type": "arc",
    "innerRadius": 0.6,
    "startAngle": -1.5707963267948966,
    "endAngle": 1.5707963267948966
  },
  "data": [/* 2 rows, as in the Spec tab; Copy includes them */],
  "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."
  }
};

const container = document.getElementById("chart");
if (!container) throw new Error('Add <div id="chart"></div> to the page first.');
createChart(container, spec);

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.
  • Waffle shows shares as countable squares.
  • Parliament shows seats in a hemicycle.
  • Stacked 100% compares shares across several wholes.
  • Bar ranks categories when there are too many for a pie.
  • Marks reference lists the channels and options each mark type takes.