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

# Pie

export const GraphPreview = ({config, aspectRatio = '10 / 6'}) => {
  const getThemeId = () => {
    return document.documentElement.classList.contains('dark') ? 'dark' : 'light';
  };
  const [themeId, setThemeId] = useState(getThemeId);
  const [isLoaded, setIsLoaded] = useState(false);
  config.appearance = {
    ...config.appearance,
    border: {
      style: 'none',
      color: 'transparent',
      width: 0
    },
    hasRoundedBorders: false
  };
  const baseUrl = window.location.hostname === 'localhost' ? 'https://app.graphy.top:8080' : 'https://visualize.graphy.app';
  const url = new URL('view/graph', baseUrl);
  url.searchParams.set('config', JSON.stringify(config));
  url.searchParams.set('themeId', themeId);
  useEffect(() => {
    const observer = new MutationObserver(function (mutations) {
      setThemeId(getThemeId());
    });
    observer.observe(document.documentElement, {
      attributes: true,
      attributeOldValue: true,
      attributeFilter: ['class']
    });
    return () => observer.disconnect();
  }, []);
  return <div className="graph-preview" style={{
    aspectRatio,
    opacity: isLoaded ? 1 : 0
  }}>
      <iframe src={url.toString()} loading="lazy" onLoad={() => setIsLoaded(true)} allowfullscreen="true" />
    </div>;
};

Pie charts display data as slices of a circle, showing parts of a whole as proportions.

## When to use

* **Simple part-to-whole relationships** - Show how categories contribute to a total
* **2-6 categories** - Works best with a small number of slices
* **Percentage comparison** - Emphasise relative proportions
* **Single data series** - Show one breakdown at a time

## Basic example

<GraphPreview
  config={{
type: 'pie',
data: {
  columns: [
    { key: 'browser', label: 'Browser' },
    { key: 'users', label: 'Users' },
  ],
  rows: [
    { browser: 'Chrome', users: 12500 },
    { browser: 'Safari', users: 8200 },
    { browser: 'Firefox', users: 3400 },
    { browser: 'Edge', users: 2100 },
    { browser: 'Other', users: 1800 },
  ],
},
}}
/>

```tsx theme={null}
const config: GraphConfig = {
  type: 'pie',
  data: {
    columns: [
      { key: 'browser', label: 'Browser' },
      { key: 'users', label: 'Users' },
    ],
    rows: [
      { browser: 'Chrome', users: 12500 },
      { browser: 'Safari', users: 8200 },
      { browser: 'Firefox', users: 3400 },
      { browser: 'Edge', users: 2100 },
      { browser: 'Other', users: 1800 },
    ],
  },
};
```

## Data labels

Show category labels and percentages on slices:

```tsx theme={null}
const config: GraphConfig = {
  type: 'pie',
  dataLabels: {
    showCategoryLabels: true,
    showDataLabels: true,
    dataLabelFormat: 'percentage',
  },
  data: {
    /* ... */
  },
};
```

## Related

* [Donut](/sdk/graph-types/donut) - Donut chart with hollow center
* [Type options](/sdk/config/type-options) - Pie chart options
* [Data labels](/sdk/config/data-labels) - Display values and percentages
