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

# Donut

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>;
};

Donut charts are pie charts with a hollow center, ideal for displaying a central metric alongside part-to-whole relationships.

## When to use

* **Part-to-whole with central metric** - Show breakdown with total or key value in center
* **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: 'donut',
data: {
  columns: [
    { key: 'category', label: 'Category' },
    { key: 'sales', label: 'Sales' },
  ],
  rows: [
    { category: 'Electronics', sales: 45000 },
    { category: 'Clothing', sales: 32000 },
    { category: 'Home & Garden', sales: 28000 },
    { category: 'Sports', sales: 18000 },
    { category: 'Books', sales: 12000 },
  ],
},
}}
/>

```tsx theme={null}
const config: GraphConfig = {
  type: 'donut',
  data: {
    columns: [
      { key: 'category', label: 'Category' },
      { key: 'sales', label: 'Sales' },
    ],
    rows: [
      { category: 'Electronics', sales: 45000 },
      { category: 'Clothing', sales: 32000 },
      { category: 'Home & Garden', sales: 28000 },
      { category: 'Sports', sales: 18000 },
      { category: 'Books', sales: 12000 },
    ],
  },
};
```

## Data labels

Show category labels and percentages on slices:

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

## Related

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