> ## Documentation Index
> Fetch the complete documentation index at: https://prefab.prefect.io/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# PieChart

> Visualize proportions with slices of a circle.

export const ComponentPreview = ({json, height, resizable, bare, hideJson, playground, children}) => {
  const hostRef = React.useRef(null);
  const handleRef = React.useRef(null);
  const cardRef = React.useRef(null);
  const containerRef = React.useRef(null);
  const [previewWidth, setPreviewWidth] = React.useState(null);
  const [isDragging, setIsDragging] = React.useState(false);
  const [playgroundHref, setPlaygroundHref] = React.useState(null);
  React.useEffect(function () {
    if (!playground) return;
    var isLocal = location.hostname === "localhost" || location.hostname === "127.0.0.1";
    var path = isLocal ? "/playground" : "/docs/playground";
    var url = new URL(path, window.location.href);
    url.hash = "code=" + playground;
    setPlaygroundHref(url.href);
  }, [playground]);
  var jsonStr = typeof json === "string" ? json : JSON.stringify(json, null, 2);
  React.useEffect(function () {
    if (cardRef.current) {
      var card = cardRef.current.closest(".group");
      if (card) card.classList.remove("group");
    }
    var host = hostRef.current;
    if (!host || !json) return;
    function mount() {
      if (!window.__prefab || !host) return;
      var dark = document.documentElement.classList.contains("dark");
      handleRef.current = window.__prefab.mountPreview(host, jsonStr, {
        dark: dark
      });
      if (bare && host.shadowRoot) {
        var m = host.shadowRoot.querySelector("[data-prefab-mount]");
        if (m) m.style.background = "transparent";
      }
    }
    if (window.__prefab) {
      mount();
    } else {
      if (!window.__prefabLoading) {
        if (!window.__prefabReady) {
          var s = document.createElement("script");
          s.src = "/renderer.js";
          document.head.appendChild(s);
        }
        window.__prefabLoading = new Promise(function (resolve) {
          function check() {
            if (window.__prefabReady) {
              window.__prefabReady.then(resolve);
            } else {
              setTimeout(check, 10);
            }
          }
          check();
        });
      }
      window.__prefabLoading.then(mount);
    }
    var observer = new MutationObserver(function () {
      var dark = document.documentElement.classList.contains("dark");
      if (handleRef.current) handleRef.current.setDark(dark);
    });
    observer.observe(document.documentElement, {
      attributes: true,
      attributeFilter: ["class"]
    });
    return function () {
      observer.disconnect();
      if (handleRef.current) {
        handleRef.current.unmount();
        handleRef.current = null;
      }
    };
  }, [json]);
  function startResize(e) {
    e.preventDefault();
    var startX = e.clientX;
    var startW = hostRef.current ? hostRef.current.offsetWidth : 0;
    var maxW = containerRef.current ? containerRef.current.offsetWidth - 10 : startW;
    setIsDragging(true);
    function onMove(ev) {
      var w = Math.max(260, Math.min(startW + (ev.clientX - startX), maxW));
      setPreviewWidth(w);
    }
    function onUp() {
      document.removeEventListener("mousemove", onMove);
      document.removeEventListener("mouseup", onUp);
      setIsDragging(false);
    }
    document.addEventListener("mousemove", onMove);
    document.addEventListener("mouseup", onUp);
  }
  if (bare) {
    return <div ref={hostRef} />;
  }
  if (resizable) {
    return <Card>
        <div ref={cardRef} />
        <div ref={containerRef} style={{
      display: "flex",
      position: "relative",
      overflow: "hidden"
    }}>
          <div ref={hostRef} style={{
      flex: previewWidth ? "none" : 1,
      width: previewWidth ? previewWidth + "px" : undefined,
      minWidth: 0
    }} />
          <div onMouseDown={startResize} style={{
      width: "14px",
      flexShrink: 0,
      cursor: "col-resize",
      background: isDragging ? "var(--border, #e5e7eb)" : "color-mix(in srgb, var(--border, #e5e7eb) 40%, transparent)",
      display: "flex",
      alignItems: "center",
      justifyContent: "center",
      transition: "background 0.15s",
      userSelect: "none"
    }}>
            <svg width="6" height="24" style={{
      opacity: 0.5
    }}>
              <circle cx="2" cy="4" r="1.2" fill="currentColor" />
              <circle cx="2" cy="9" r="1.2" fill="currentColor" />
              <circle cx="2" cy="14" r="1.2" fill="currentColor" />
              <circle cx="2" cy="19" r="1.2" fill="currentColor" />
              <circle cx="5" cy="4" r="1.2" fill="currentColor" />
              <circle cx="5" cy="9" r="1.2" fill="currentColor" />
              <circle cx="5" cy="14" r="1.2" fill="currentColor" />
              <circle cx="5" cy="19" r="1.2" fill="currentColor" />
            </svg>
          </div>
          <div style={{
      flex: previewWidth ? 1 : "0 0 24px",
      minWidth: "24px",
      background: "repeating-linear-gradient(-45deg, transparent, transparent 3px, var(--border, #e5e7eb) 3px, var(--border, #e5e7eb) 4px)",
      opacity: 0.4
    }} />
          {previewWidth && <div style={{
      position: "absolute",
      bottom: "8px",
      right: "8px",
      background: "var(--background, white)",
      border: "1px solid var(--border, #e5e7eb)",
      borderRadius: "4px",
      padding: "1px 6px",
      fontSize: "11px",
      fontFamily: "monospace",
      color: "var(--muted-foreground, #6b7280)",
      pointerEvents: "none"
    }}>
              {previewWidth}px
            </div>}
        </div>
        {playgroundHref && <div style={{
      display: "flex",
      justifyContent: "flex-end",
      padding: "4px 0 8px"
    }}>
            <a href={playgroundHref} target="_blank" rel="noopener noreferrer" style={{
      fontSize: "11px",
      opacity: 0.4,
      textDecoration: "none",
      textDecorationLine: "none",
      borderBottom: "none",
      boxShadow: "none",
      display: "inline-flex",
      alignItems: "center",
      gap: "3px",
      transition: "opacity 0.15s",
      fontWeight: 400
    }} onMouseOver={function (e) {
      e.currentTarget.style.opacity = "0.6";
    }} onMouseOut={function (e) {
      e.currentTarget.style.opacity = "0.4";
    }}>
              Edit in Playground
              <svg xmlns="http://www.w3.org/2000/svg" width="11" height="11" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><path d="M15 3h6v6" /><path d="M10 14 21 3" /><path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6" /></svg>
            </a>
          </div>}
        <div style={{
      marginBottom: "-2rem"
    }}>{children}</div>
      </Card>;
  }
  return <Card>
      <div ref={cardRef} />
      <div ref={hostRef} />
      {playgroundHref && <div style={{
    display: "flex",
    justifyContent: "flex-end",
    padding: "4px 0 8px"
  }}>
          <a href={playgroundHref} target="_blank" rel="noopener noreferrer" style={{
    fontSize: "11px",
    opacity: 0.4,
    textDecoration: "none",
    textDecorationLine: "none",
    borderBottom: "none",
    boxShadow: "none",
    display: "inline-flex",
    alignItems: "center",
    gap: "3px",
    transition: "opacity 0.15s",
    fontWeight: 400
  }} onMouseOver={function (e) {
    e.currentTarget.style.opacity = "0.6";
  }} onMouseOut={function (e) {
    e.currentTarget.style.opacity = "0.4";
  }}>
            Edit in Playground
            <svg xmlns="http://www.w3.org/2000/svg" width="11" height="11" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><path d="M15 3h6v6" /><path d="M10 14 21 3" /><path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6" /></svg>
          </a>
        </div>}
      <div style={{
    marginBottom: "-2rem"
  }}>{children}</div>
    </Card>;
};

PieChart shows how parts relate to a whole. Unlike the other chart types, it doesn't use series — instead you specify which data field holds the numeric values (`data_key`) and which holds the labels (`name_key`). Set `inner_radius` to turn it into a donut chart.

## Basic Usage

<ComponentPreview json={{"view":{"type":"PieChart","data":[{"browser":"Chrome","visitors":275},{"browser":"Safari","visitors":200},{"browser":"Firefox","visitors":187},{"browser":"Edge","visitors":173},{"browser":"Other","visitors":90}],"dataKey":"visitors","nameKey":"browser","height":300,"innerRadius":0,"showLabel":false,"paddingAngle":0,"showLegend":true,"showTooltip":true,"animate":true,"valueFormat":"auto"}}} playground="ZnJvbSBwcmVmYWJfdWkuY29tcG9uZW50cy5jaGFydHMgaW1wb3J0IFBpZUNoYXJ0CgpkYXRhID0gWwogICAgeyJicm93c2VyIjogIkNocm9tZSIsICJ2aXNpdG9ycyI6IDI3NX0sCiAgICB7ImJyb3dzZXIiOiAiU2FmYXJpIiwgInZpc2l0b3JzIjogMjAwfSwKICAgIHsiYnJvd3NlciI6ICJGaXJlZm94IiwgInZpc2l0b3JzIjogMTg3fSwKICAgIHsiYnJvd3NlciI6ICJFZGdlIiwgInZpc2l0b3JzIjogMTczfSwKICAgIHsiYnJvd3NlciI6ICJPdGhlciIsICJ2aXNpdG9ycyI6IDkwfSwKXQoKUGllQ2hhcnQoCiAgICBkYXRhPWRhdGEsCiAgICBkYXRhX2tleT0idmlzaXRvcnMiLAogICAgbmFtZV9rZXk9ImJyb3dzZXIiLAogICAgc2hvd19sZWdlbmQ9VHJ1ZSwKKQo">
  <CodeGroup>
    ```python Python icon="python" theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
    from prefab_ui.components.charts import PieChart

    data = [
        {"browser": "Chrome", "visitors": 275},
        {"browser": "Safari", "visitors": 200},
        {"browser": "Firefox", "visitors": 187},
        {"browser": "Edge", "visitors": 173},
        {"browser": "Other", "visitors": 90},
    ]

    PieChart(
        data=data,
        data_key="visitors",
        name_key="browser",
        show_legend=True,
    )
    ```

    ```json Protocol icon="brackets-curly" theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
    {
      "view": {
        "type": "PieChart",
        "data": [
          {"browser": "Chrome", "visitors": 275},
          {"browser": "Safari", "visitors": 200},
          {"browser": "Firefox", "visitors": 187},
          {"browser": "Edge", "visitors": 173},
          {"browser": "Other", "visitors": 90}
        ],
        "dataKey": "visitors",
        "nameKey": "browser",
        "height": 300,
        "innerRadius": 0,
        "showLabel": false,
        "paddingAngle": 0,
        "showLegend": true,
        "showTooltip": true,
        "animate": true,
        "valueFormat": "auto"
      }
    }
    ```
  </CodeGroup>
</ComponentPreview>

## Donut Chart

Set `inner_radius` to a value greater than 0 to hollow out the center. This creates a donut chart, which can feel cleaner and leaves room for a central label or statistic.

<ComponentPreview json={{"view":{"type":"PieChart","data":[{"browser":"Chrome","visitors":275},{"browser":"Safari","visitors":200},{"browser":"Firefox","visitors":187},{"browser":"Edge","visitors":173},{"browser":"Other","visitors":90}],"dataKey":"visitors","nameKey":"browser","height":300,"innerRadius":60,"showLabel":false,"paddingAngle":0,"showLegend":true,"showTooltip":true,"animate":true,"valueFormat":"auto"}}} playground="UGllQ2hhcnQoCiAgICBkYXRhPVsKICAgICAgICB7ImJyb3dzZXIiOiAiQ2hyb21lIiwgInZpc2l0b3JzIjogMjc1fSwKICAgICAgICB7ImJyb3dzZXIiOiAiU2FmYXJpIiwgInZpc2l0b3JzIjogMjAwfSwKICAgICAgICB7ImJyb3dzZXIiOiAiRmlyZWZveCIsICJ2aXNpdG9ycyI6IDE4N30sCiAgICAgICAgeyJicm93c2VyIjogIkVkZ2UiLCAidmlzaXRvcnMiOiAxNzN9LAogICAgICAgIHsiYnJvd3NlciI6ICJPdGhlciIsICJ2aXNpdG9ycyI6IDkwfSwKICAgIF0sCiAgICBkYXRhX2tleT0idmlzaXRvcnMiLAogICAgbmFtZV9rZXk9ImJyb3dzZXIiLAogICAgaW5uZXJfcmFkaXVzPTYwLAogICAgc2hvd19sZWdlbmQ9VHJ1ZSwKKQo">
  <CodeGroup>
    ```python Python icon="python" theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
    PieChart(
        data=[
            {"browser": "Chrome", "visitors": 275},
            {"browser": "Safari", "visitors": 200},
            {"browser": "Firefox", "visitors": 187},
            {"browser": "Edge", "visitors": 173},
            {"browser": "Other", "visitors": 90},
        ],
        data_key="visitors",
        name_key="browser",
        inner_radius=60,
        show_legend=True,
    )
    ```

    ```json Protocol icon="brackets-curly" theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
    {
      "view": {
        "type": "PieChart",
        "data": [
          {"browser": "Chrome", "visitors": 275},
          {"browser": "Safari", "visitors": 200},
          {"browser": "Firefox", "visitors": 187},
          {"browser": "Edge", "visitors": 173},
          {"browser": "Other", "visitors": 90}
        ],
        "dataKey": "visitors",
        "nameKey": "browser",
        "height": 300,
        "innerRadius": 60,
        "showLabel": false,
        "paddingAngle": 0,
        "showLegend": true,
        "showTooltip": true,
        "animate": true,
        "valueFormat": "auto"
      }
    }
    ```
  </CodeGroup>
</ComponentPreview>

## Labels

Set `show_label=True` to display a label on each slice, making values readable without tooltips.

<ComponentPreview json={{"view":{"type":"PieChart","data":[{"browser":"Chrome","visitors":275},{"browser":"Safari","visitors":200},{"browser":"Firefox","visitors":187},{"browser":"Edge","visitors":173},{"browser":"Other","visitors":90}],"dataKey":"visitors","nameKey":"browser","height":300,"innerRadius":0,"showLabel":true,"paddingAngle":0,"showLegend":true,"showTooltip":true,"animate":true,"valueFormat":"auto"}}} playground="UGllQ2hhcnQoCiAgICBkYXRhPWRhdGEsCiAgICBkYXRhX2tleT0idmlzaXRvcnMiLAogICAgbmFtZV9rZXk9ImJyb3dzZXIiLAogICAgc2hvd19sYWJlbD1UcnVlLAogICAgc2hvd19sZWdlbmQ9VHJ1ZSwKKQo">
  <CodeGroup>
    ```python Python {5} icon="python" theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
    PieChart(
        data=data,
        data_key="visitors",
        name_key="browser",
        show_label=True,
        show_legend=True,
    )
    ```

    ```json Protocol icon="brackets-curly" theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
    {
      "view": {
        "type": "PieChart",
        "data": [
          {"browser": "Chrome", "visitors": 275},
          {"browser": "Safari", "visitors": 200},
          {"browser": "Firefox", "visitors": 187},
          {"browser": "Edge", "visitors": 173},
          {"browser": "Other", "visitors": 90}
        ],
        "dataKey": "visitors",
        "nameKey": "browser",
        "height": 300,
        "innerRadius": 0,
        "showLabel": true,
        "paddingAngle": 0,
        "showLegend": true,
        "showTooltip": true,
        "animate": true,
        "valueFormat": "auto"
      }
    }
    ```
  </CodeGroup>
</ComponentPreview>

## Spaced Slices

Set `padding_angle` to add space between slices, visually separating each segment.

<ComponentPreview json={{"view":{"type":"PieChart","data":[{"browser":"Chrome","visitors":275},{"browser":"Safari","visitors":200},{"browser":"Firefox","visitors":187},{"browser":"Edge","visitors":173},{"browser":"Other","visitors":90}],"dataKey":"visitors","nameKey":"browser","height":300,"innerRadius":60,"showLabel":false,"paddingAngle":5,"showLegend":true,"showTooltip":true,"animate":true,"valueFormat":"auto"}}} playground="UGllQ2hhcnQoCiAgICBkYXRhPWRhdGEsCiAgICBkYXRhX2tleT0idmlzaXRvcnMiLAogICAgbmFtZV9rZXk9ImJyb3dzZXIiLAogICAgaW5uZXJfcmFkaXVzPTYwLAogICAgcGFkZGluZ19hbmdsZT01LAogICAgc2hvd19sZWdlbmQ9VHJ1ZSwKKQo">
  <CodeGroup>
    ```python Python {6} icon="python" theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
    PieChart(
        data=data,
        data_key="visitors",
        name_key="browser",
        inner_radius=60,
        padding_angle=5,
        show_legend=True,
    )
    ```

    ```json Protocol icon="brackets-curly" theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
    {
      "view": {
        "type": "PieChart",
        "data": [
          {"browser": "Chrome", "visitors": 275},
          {"browser": "Safari", "visitors": 200},
          {"browser": "Firefox", "visitors": 187},
          {"browser": "Edge", "visitors": 173},
          {"browser": "Other", "visitors": 90}
        ],
        "dataKey": "visitors",
        "nameKey": "browser",
        "height": 300,
        "innerRadius": 60,
        "showLabel": false,
        "paddingAngle": 5,
        "showLegend": true,
        "showTooltip": true,
        "animate": true,
        "valueFormat": "auto"
      }
    }
    ```
  </CodeGroup>
</ComponentPreview>

## Tooltip Formatting

Use `value_format` to format tooltip values with the same pipe strings as Prefab expressions and data table columns. Percent formatting expects fractional values, so `0.42` renders as `42%`.

<ComponentPreview json={{"view":{"type":"PieChart","data":[{"category":"Compute","share":0.42},{"category":"Storage","share":0.24},{"category":"Network","share":0.18},{"category":"Support","share":0.16}],"dataKey":"share","nameKey":"category","height":300,"innerRadius":0,"showLabel":false,"paddingAngle":0,"showLegend":true,"showTooltip":true,"animate":true,"valueFormat":"percent:1"}}} playground="ZnJvbSBwcmVmYWJfdWkuY29tcG9uZW50cy5jaGFydHMgaW1wb3J0IFBpZUNoYXJ0CgpkYXRhID0gWwogICAgeyJjYXRlZ29yeSI6ICJDb21wdXRlIiwgInNoYXJlIjogMC40Mn0sCiAgICB7ImNhdGVnb3J5IjogIlN0b3JhZ2UiLCAic2hhcmUiOiAwLjI0fSwKICAgIHsiY2F0ZWdvcnkiOiAiTmV0d29yayIsICJzaGFyZSI6IDAuMTh9LAogICAgeyJjYXRlZ29yeSI6ICJTdXBwb3J0IiwgInNoYXJlIjogMC4xNn0sCl0KClBpZUNoYXJ0KAogICAgZGF0YT1kYXRhLAogICAgZGF0YV9rZXk9InNoYXJlIiwKICAgIG5hbWVfa2V5PSJjYXRlZ29yeSIsCiAgICB2YWx1ZV9mb3JtYXQ9InBlcmNlbnQ6MSIsCiAgICBzaG93X2xlZ2VuZD1UcnVlLAopCg">
  <CodeGroup>
    ```python icon="python" theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
    from prefab_ui.components.charts import PieChart

    data = [
        {"category": "Compute", "share": 0.42},
        {"category": "Storage", "share": 0.24},
        {"category": "Network", "share": 0.18},
        {"category": "Support", "share": 0.16},
    ]

    PieChart(
        data=data,
        data_key="share",
        name_key="category",
        value_format="percent:1",
        show_legend=True,
    )
    ```

    ```json Protocol icon="brackets-curly" theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
    {
      "view": {
        "type": "PieChart",
        "data": [
          {"category": "Compute", "share": 0.42},
          {"category": "Storage", "share": 0.24},
          {"category": "Network", "share": 0.18},
          {"category": "Support", "share": 0.16}
        ],
        "dataKey": "share",
        "nameKey": "category",
        "height": 300,
        "innerRadius": 0,
        "showLabel": false,
        "paddingAngle": 0,
        "showLegend": true,
        "showTooltip": true,
        "animate": true,
        "valueFormat": "percent:1"
      }
    }
    ```
  </CodeGroup>
</ComponentPreview>

## API Reference

<Card icon="code" title="PieChart Parameters">
  <ParamField body="data" type="list[dict] | str" required>
    Data as a list of dicts, or a `{{ field }}` interpolation reference.
  </ParamField>

  <ParamField body="data_key" type="str" required>
    The data field containing numeric values to plot as slice sizes.
  </ParamField>

  <ParamField body="name_key" type="str" required>
    The data field containing labels for each slice.
  </ParamField>

  <ParamField body="height" type="int" default="300">
    Chart height in pixels.
  </ParamField>

  <ParamField body="inner_radius" type="int" default="0">
    Inner radius in pixels. Set greater than 0 for a donut chart.
  </ParamField>

  <ParamField body="show_label" type="bool" default="False">
    Show a label on each slice.
  </ParamField>

  <ParamField body="padding_angle" type="int" default="0">
    Angle in degrees between slices.
  </ParamField>

  <ParamField body="show_legend" type="bool" default="False">
    Show a legend below the chart.
  </ParamField>

  <ParamField body="show_tooltip" type="bool" default="True">
    Show tooltips on hover.
  </ParamField>

  <ParamField body="value_format" type="str" default="&#x22;auto&#x22;">
    Format tooltip values with an expression pipe such as `currency`, `currency:EUR`, `percent:1`, or `compact:0`.
  </ParamField>

  <ParamField body="css_class" type="str | None" default="None">
    Additional Tailwind CSS classes.
  </ParamField>
</Card>

## Protocol Reference

```json PieChart theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
{
  "type": "PieChart",
  "id?": "string",
  "onMount?": "any",
  "data": "object[] | string (required)",
  "dataKey": "string (required)",
  "nameKey": "string (required)",
  "height?": "300",
  "innerRadius?": 0,
  "showLabel?": false,
  "paddingAngle?": 0,
  "showLegend?": true,
  "showTooltip?": true,
  "animate?": true,
  "valueFormat?": "string",
  "cssClass?": "string"
}
```

For the complete protocol schema, see [PieChart](/protocol/pie-chart).
