# Pie Chart

Ten pie and donut charts for showing parts of a whole, with labels, legends, a centered total, nested rings and highlighted slices.

Pie Chart is an open-source chart from suiss/ui for React, React Native, SwiftUI and Jetpack Compose. The @esuiss/ui CLI copies its source into your project, so you own the code.

Source: https://suiss.app/ui/docs/charts/pie-chart

Pie charts show how a whole splits into a few parts. Use the default pie or a donut for up to five or six slices, put the total in the center of a donut, and label slices directly or with a legend when the names are long. The nested variant shows groups and their members in two rings, and the active and separated variants draw attention to one slice.

Each chart is built on the [Chart](https://suiss.app/ui/docs/components/chart) and [Card](https://suiss.app/ui/docs/components/card) components.

Every variant below is its own registry item, so you can add only the ones you need. Each one renders the same design on React, React Native, SwiftUI and Jetpack Compose.


## Pie Chart Default

A full pie split into five device slices, separated by thin card-colored borders.

Source: https://suiss.app/ui/docs/charts/pie-chart#default

**React**

**Example**

```tsx title="components/charts/pie-chart-default.tsx"
"use client"

import { Pie, PieChart } from "recharts"

import {
  Card,
  CardContent,
  CardDescription,
  CardHeader,
  CardTitle,
} from "@/components/ui/card"
import {
  type ChartConfig,
  ChartContainer,
  ChartTooltip,
  ChartTooltipContent,
} from "@/components/ui/chart"

const chartData = [
  { device: "phone", users: 275, fill: "var(--color-phone)" },
  { device: "laptop", users: 200, fill: "var(--color-laptop)" },
  { device: "tablet", users: 187, fill: "var(--color-tablet)" },
  { device: "watch", users: 173, fill: "var(--color-watch)" },
  { device: "other", users: 90, fill: "var(--color-other)" },
]

const chartConfig = {
  users: { label: "Users" },
  phone: { label: "Phone", color: "var(--chart-1)" },
  laptop: { label: "Laptop", color: "var(--chart-2)" },
  tablet: { label: "Tablet", color: "var(--chart-3)" },
  watch: { label: "Watch", color: "var(--chart-4)" },
  other: { label: "Other", color: "var(--chart-5)" },
} satisfies ChartConfig

export function PieChartDefault() {
  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>Pie chart</CardTitle>
        <CardDescription>Users by device · thousands</CardDescription>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          className="aspect-auto h-52 w-full"
        >
          <PieChart accessibilityLayer>
            <ChartTooltip
              cursor={false}
              content={<ChartTooltipContent hideLabel nameKey="device" />}
            />
            <Pie
              data={chartData}
              dataKey="users"
              nameKey="device"
              outerRadius="85%"
              stroke="var(--muted)"
              strokeWidth={2}
            />
          </PieChart>
        </ChartContainer>
      </CardContent>
    </Card>
  )
}
```

A full pie split into five slices separated by thin gaps, with a tooltip for each slice. Use it for a quick part-to-whole view of a small number of categories.

Give each record a category key, a value and a `fill` that references its color, and add a label and color for every key to `chartConfig`. Point `dataKey` and `nameKey` on the `Pie` at your value and category fields. Pies work best with about five slices or fewer; group the rest into an Other slice.

### Installation

**Command**

```bash title="Terminal"
npx shadcn@latest add @esuiss/pie-chart-default
```

Works in any project with a `components.json`. See [Installation](https://suiss.app/ui/docs/installation#add-components) for the one-line registry setup. Or use the [suiss/ui CLI](https://suiss.app/ui/docs/cli):

```bash title="Terminal"
npx @esuiss/ui@latest add charts pie-chart-default
```

**Manual**

1. Install the following dependencies:

```bash title="Terminal"
npm install recharts
```

2. Add the pieces it builds on: [Card](https://suiss.app/ui/docs/components/card), [Chart](https://suiss.app/ui/docs/components/chart).

3. Copy and paste the following code into your project.

```tsx title="components/charts/pie-chart-default.tsx"
"use client"

import { Pie, PieChart } from "recharts"

import {
  Card,
  CardContent,
  CardDescription,
  CardHeader,
  CardTitle,
} from "@/components/ui/card"
import {
  type ChartConfig,
  ChartContainer,
  ChartTooltip,
  ChartTooltipContent,
} from "@/components/ui/chart"

const chartData = [
  { device: "phone", users: 275, fill: "var(--color-phone)" },
  { device: "laptop", users: 200, fill: "var(--color-laptop)" },
  { device: "tablet", users: 187, fill: "var(--color-tablet)" },
  { device: "watch", users: 173, fill: "var(--color-watch)" },
  { device: "other", users: 90, fill: "var(--color-other)" },
]

const chartConfig = {
  users: { label: "Users" },
  phone: { label: "Phone", color: "var(--chart-1)" },
  laptop: { label: "Laptop", color: "var(--chart-2)" },
  tablet: { label: "Tablet", color: "var(--chart-3)" },
  watch: { label: "Watch", color: "var(--chart-4)" },
  other: { label: "Other", color: "var(--chart-5)" },
} satisfies ChartConfig

export function PieChartDefault() {
  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>Pie chart</CardTitle>
        <CardDescription>Users by device · thousands</CardDescription>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          className="aspect-auto h-52 w-full"
        >
          <PieChart accessibilityLayer>
            <ChartTooltip
              cursor={false}
              content={<ChartTooltipContent hideLabel nameKey="device" />}
            />
            <Pie
              data={chartData}
              dataKey="users"
              nameKey="device"
              outerRadius="85%"
              stroke="var(--muted)"
              strokeWidth={2}
            />
          </PieChart>
        </ChartContainer>
      </CardContent>
    </Card>
  )
}
```

4. Update the import paths to match your project setup.

### Usage

```tsx
import { PieChartDefault } from "@/components/charts/pie-chart-default"
```

```tsx
<PieChartDefault />
```

**React Native, SwiftUI, Jetpack Compose**

```tsx title="uniwind/components/charts/pie-chart-default.tsx"
import {
  Card,
  CardContent,
  CardDescription,
  CardHeader,
  CardTitle,
} from "@/components/ui/card"
import {
  type ChartConfig,
  ChartContainer,
  ChartTooltip,
  ChartTooltipContent,
  Pie,
  PieChart,
} from "@/components/ui/chart"

const chartData = [
  { device: "phone", users: 275 },
  { device: "laptop", users: 200 },
  { device: "tablet", users: 187 },
  { device: "watch", users: 173 },
  { device: "other", users: 90 },
]

const chartConfig = {
  users: { label: "Users" },
  phone: { label: "Phone", color: "chart-1" },
  laptop: { label: "Laptop", color: "chart-2" },
  tablet: { label: "Tablet", color: "chart-3" },
  watch: { label: "Watch", color: "chart-4" },
  other: { label: "Other", color: "chart-5" },
} satisfies ChartConfig

export function PieChartDefault() {
  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>Pie chart</CardTitle>
        <CardDescription>Users by device · thousands</CardDescription>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          accessibilityLabel="Pie chart"
          className="h-52 w-full"
        >
          <PieChart>
            <ChartTooltip
              cursor={false}
              content={<ChartTooltipContent hideLabel nameKey="device" />}
            />
            <Pie
              data={chartData}
              dataKey="users"
              nameKey="device"
              outerRadius="85%"
              stroke="muted"
              strokeWidth={2}
            />
          </PieChart>
        </ChartContainer>
      </CardContent>
    </Card>
  )
}
```

```swift title="swift/Charts/PieChartDefault.swift"
import Charts
import SwiftUI

private let chartData: [(device: String, users: Double)] = [
  ("phone", 275), ("laptop", 200), ("tablet", 187), ("watch", 173), ("other", 90),
]

private let chartConfig: ChartConfig = [
  "users": .init("Users"),
  "phone": .init("Phone", color: EsuissColor.chart1),
  "laptop": .init("Laptop", color: EsuissColor.chart2),
  "tablet": .init("Tablet", color: EsuissColor.chart3),
  "watch": .init("Watch", color: EsuissColor.chart4),
  "other": .init("Other", color: EsuissColor.chart5),
]

public struct PieChartDefault: View {
  @State private var selection: Int?

  public init() {}

  public var body: some View {
    Card(.filled, size: .sm) {
      CardHeader("Pie chart", description: "Users by device · thousands")
      CardContent {
        ChartContainer(config: chartConfig) {
          ChartAnimator { progress in
            Chart {
              ForEach(chartData, id: \.device) { item in
                SectorMark(angle: .value("Users", item.users * progress), outerRadius: .ratio(0.85), angularInset: 1)
                  .foregroundStyle(chartConfig.color(item.device))
              }
              ChartSectorRest(total: chartData.reduce(0) { $0 + $1.users }, progress: progress)
            }
            .chartTooltip(
              angle: chartData.map(\.users),
              labels: chartData.map { chartConfig.label($0.device) },
              outerRadius: 0.85,
              selection: $selection,
              accessibilityLabel: "Pie chart",
              items: { [ChartTooltipItem(chartData[$0].device, value: chartData[$0].users)] }
            ) { payload in
              ChartTooltipContent(payload, hideLabel: true)
            }
            .padding(5)
          }
        }
        .frame(height: 208)
      }
    }
  }
}
```

```kt title="kotlin/charts/PieChartDefault.kt"
package com.esuiss.ui.charts

import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.esuiss.ui.components.Card
import com.esuiss.ui.components.CardContent
import com.esuiss.ui.components.CardHeader
import com.esuiss.ui.components.CardSize
import com.esuiss.ui.components.CardVariant
import com.esuiss.ui.components.ChartConfig
import com.esuiss.ui.components.ChartConfigItem
import com.esuiss.ui.components.ChartContainer
import com.esuiss.ui.components.ChartTooltipContent
import com.esuiss.ui.components.PieChart
import com.esuiss.ui.theme.EsuissTheme

private class PieDefaultDeviceUsers(val device: String, val users: Double)

private val chartData = listOf(
    PieDefaultDeviceUsers("phone", 275.0),
    PieDefaultDeviceUsers("laptop", 200.0),
    PieDefaultDeviceUsers("tablet", 187.0),
    PieDefaultDeviceUsers("watch", 173.0),
    PieDefaultDeviceUsers("other", 90.0),
)

private val chartConfig = ChartConfig(
    "users" to ChartConfigItem("Users"),
    "phone" to ChartConfigItem("Phone") { chart1 },
    "laptop" to ChartConfigItem("Laptop") { chart2 },
    "tablet" to ChartConfigItem("Tablet") { chart3 },
    "watch" to ChartConfigItem("Watch") { chart4 },
    "other" to ChartConfigItem("Other") { chart5 },
)

@Composable
fun PieChartDefault(modifier: Modifier = Modifier) {
    val colors = EsuissTheme.colors
    Card(modifier, variant = CardVariant.Filled, size = CardSize.Sm) {
        CardHeader("Pie chart", description = "Users by device · thousands")
        CardContent {
            ChartContainer(
                chartConfig,
                Modifier
                    .fillMaxWidth()
                    .height(208.dp),
            ) {
                PieChart(accessibilityLabel = "Pie chart") {
                    ChartTooltip { ChartTooltipContent(hideLabel = true) }
                    Pie(
                        chartData,
                        value = { it.users },
                        nameKey = { it.device },
                        outerRadius = 0.85f,
                        stroke = colors.muted,
                        strokeWidth = 2.dp,
                    )
                }
            }
        }
    }
}
```

**React Native, Jetpack Compose**

The simplest `PieChart`: one `Pie` inside a `Card`, with slices separated by a thin stroke in the card color. `chartData` holds one record per device with a `users` count. Pressing a slice shows a tooltip with its name and value.

**React Native**

Replace `chartData` with your records and keep `dataKey` and `nameKey` in step with your field names. Add one entry per slice to `chartConfig` with its label and color; the component takes no props.

**React Native, SwiftUI, Jetpack Compose**

### Installation

**Command**

**React Native**

```bash title="Terminal"
npx shadcn@latest add @esuiss/pie-chart-default
```

See [Installation](https://suiss.app/ui/docs/installation) for the `components.json` setup. Or use the [suiss/ui CLI](https://suiss.app/ui/docs/cli):

```bash title="Terminal"
npx @esuiss/ui@latest add charts pie-chart-default
```

**SwiftUI**

```bash title="Terminal"
npx shadcn@latest add @esuiss/pie-chart-default
```

See [Installation](https://suiss.app/ui/docs/installation) for the `components.json` setup. Or use the [suiss/ui CLI](https://suiss.app/ui/docs/cli):

```bash title="Terminal"
npx @esuiss/ui@latest add charts pie-chart-default --platform swift
```

**Jetpack Compose**

```bash title="Terminal"
npx shadcn@latest add @esuiss/pie-chart-default
```

See [Installation](https://suiss.app/ui/docs/installation) for the `components.json` setup. Or use the [suiss/ui CLI](https://suiss.app/ui/docs/cli):

```bash title="Terminal"
npx @esuiss/ui@latest add charts pie-chart-default --platform kotlin
```

**React Native**

The CLI also adds what it builds on: [Card](https://suiss.app/ui/docs/components/card), [Chart](https://suiss.app/ui/docs/components/chart).

**React Native, SwiftUI, Jetpack Compose**

**Manual**

**React Native**

**Uniwind**

1. Add the pieces it builds on: [Card](https://suiss.app/ui/docs/components/card), [Chart](https://suiss.app/ui/docs/components/chart).

2. Copy and paste the following code into `components/charts/pie-chart-default.tsx`:

- `uniwind/components/charts/pie-chart-default.tsx`: shown above

3. Update the import paths to match your project setup.

**NativeWind**

1. Add the pieces it builds on: [Card](https://suiss.app/ui/docs/components/card), [Chart](https://suiss.app/ui/docs/components/chart).

2. Copy and paste the following code into `components/charts/pie-chart-default.tsx`:

```tsx title="nativewind/components/charts/pie-chart-default.tsx"
import {
  Card,
  CardContent,
  CardDescription,
  CardHeader,
  CardTitle,
} from "@/components/ui/card"
import {
  type ChartConfig,
  ChartContainer,
  ChartTooltip,
  ChartTooltipContent,
  Pie,
  PieChart,
} from "@/components/ui/chart"

const chartData = [
  { device: "phone", users: 275 },
  { device: "laptop", users: 200 },
  { device: "tablet", users: 187 },
  { device: "watch", users: 173 },
  { device: "other", users: 90 },
]

const chartConfig = {
  users: { label: "Users" },
  phone: { label: "Phone", color: "chart-1" },
  laptop: { label: "Laptop", color: "chart-2" },
  tablet: { label: "Tablet", color: "chart-3" },
  watch: { label: "Watch", color: "chart-4" },
  other: { label: "Other", color: "chart-5" },
} satisfies ChartConfig

export function PieChartDefault() {
  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>Pie chart</CardTitle>
        <CardDescription>Users by device · thousands</CardDescription>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          accessibilityLabel="Pie chart"
          className="h-52 w-full"
        >
          <PieChart>
            <ChartTooltip
              cursor={false}
              content={<ChartTooltipContent hideLabel nameKey="device" />}
            />
            <Pie
              data={chartData}
              dataKey="users"
              nameKey="device"
              outerRadius="85%"
              stroke="muted"
              strokeWidth={2}
            />
          </PieChart>
        </ChartContainer>
      </CardContent>
    </Card>
  )
}
```

3. Update the import paths to match your project setup.

**StyleSheet**

1. Add the pieces it builds on: [Card](https://suiss.app/ui/docs/components/card), [Chart](https://suiss.app/ui/docs/components/chart).

2. Copy and paste the following code into `components/charts/pie-chart-default.tsx`:

```tsx title="stylesheet/components/charts/pie-chart-default.tsx"
import {
  Card,
  CardContent,
  CardDescription,
  CardHeader,
  CardTitle,
} from "@/components/ui/card"
import {
  type ChartConfig,
  ChartContainer,
  ChartTooltip,
  ChartTooltipContent,
  Pie,
  PieChart,
} from "@/components/ui/chart"

const chartData = [
  { device: "phone", users: 275 },
  { device: "laptop", users: 200 },
  { device: "tablet", users: 187 },
  { device: "watch", users: 173 },
  { device: "other", users: 90 },
]

const chartConfig = {
  users: { label: "Users" },
  phone: { label: "Phone", color: "chart-1" },
  laptop: { label: "Laptop", color: "chart-2" },
  tablet: { label: "Tablet", color: "chart-3" },
  watch: { label: "Watch", color: "chart-4" },
  other: { label: "Other", color: "chart-5" },
} satisfies ChartConfig

export function PieChartDefault() {
  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>Pie chart</CardTitle>
        <CardDescription>Users by device · thousands</CardDescription>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          accessibilityLabel="Pie chart"
          style={{ height: 208 }}
        >
          <PieChart>
            <ChartTooltip
              cursor={false}
              content={<ChartTooltipContent hideLabel nameKey="device" />}
            />
            <Pie
              data={chartData}
              dataKey="users"
              nameKey="device"
              outerRadius="85%"
              stroke="muted"
              strokeWidth={2}
            />
          </PieChart>
        </ChartContainer>
      </CardContent>
    </Card>
  )
}
```

3. Update the import paths to match your project setup.

**SwiftUI**

1. Target iOS 17 or later.

2. Copy the theme files every view uses:

- `swift/Theme/Theme.swift`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/swiftui/Sources/EsuissUI/Theme/Theme.swift)

- `swift/Theme/Tokens.swift`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/swiftui/Sources/EsuissUI/Theme/Tokens.swift)

3. Copy the source and every file it uses:

- `swift/Charts/PieChartDefault.swift`: shown above

- `swift/Components/Card.swift`: see [Card](https://suiss.app/ui/docs/components/card.md)

- `swift/Components/Chart.swift`: see [Chart](https://suiss.app/ui/docs/components/chart.md)

- `swift/Components/Haptics.swift`: see [Haptics](https://suiss.app/ui/docs/components/haptics.md)

- `swift/Components/Item.swift`: see [Item](https://suiss.app/ui/docs/components/item.md)

- `swift/Components/Separator.swift`: see [Separator](https://suiss.app/ui/docs/components/separator.md)

4. Add the files to your app target.

**Jetpack Compose**

1. Apply the Compose compiler plugin, enable Compose, set `compileSdk` to 37 or higher and `minSdk` to 24 or higher, and add the dependencies:

```kotlin title="build.gradle.kts"
plugins {
    id("org.jetbrains.kotlin.plugin.compose")
}

android {
    compileSdk = 37
    defaultConfig { minSdk = 24 }
    buildFeatures { compose = true }
}

dependencies {
    implementation(platform("androidx.compose:compose-bom:2026.09.00"))
    implementation("androidx.compose.foundation:foundation")
    implementation("androidx.compose.ui:ui")
}
```

2. Copy the theme files every view uses:

- `kotlin/theme/Theme.kt`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/kotlin/ui/src/main/kotlin/com/esuiss/ui/theme/Theme.kt)

- `kotlin/theme/Tokens.kt`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/kotlin/ui/src/main/kotlin/com/esuiss/ui/theme/Tokens.kt)

3. Copy the source and every file it uses:

- `kotlin/charts/PieChartDefault.kt`: shown above

- `kotlin/components/Card.kt`: see [Card](https://suiss.app/ui/docs/components/card.md)

- `kotlin/components/Chart.kt`: see [Chart](https://suiss.app/ui/docs/components/chart.md)

- `kotlin/components/Content.kt`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/kotlin/ui/src/main/kotlin/com/esuiss/ui/components/Content.kt)

- `kotlin/components/FormSupport.kt`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/kotlin/ui/src/main/kotlin/com/esuiss/ui/components/FormSupport.kt)

- `kotlin/components/Haptics.kt`: see [Haptics](https://suiss.app/ui/docs/components/haptics.md)

- `kotlin/components/Icon.kt`: see [Icon](https://suiss.app/ui/docs/components/icon.md)

4. Update the `com.esuiss.ui` package names to match your project.

**React Native, SwiftUI, Jetpack Compose**

### Usage

**React Native**

```tsx
import { PieChartDefault } from "@/components/charts/pie-chart-default"
```

```tsx
<PieChartDefault />
```

**SwiftUI**

```swift
import SwiftUI

struct PieExample: View {
  var body: some View {
    PieChartDefault()
  }
}
```

**Jetpack Compose**

```kotlin
import androidx.compose.runtime.Composable
import com.esuiss.ui.charts.PieChartDefault

@Composable
fun PieExample() {
    PieChartDefault()
}
```



## Pie Chart Active

A donut where one slice is enlarged and outlined with an outer arc to highlight it.

Source: https://suiss.app/ui/docs/charts/pie-chart#active

**React**

**Example**

```tsx title="components/charts/pie-chart-active.tsx"
"use client"

import { Pie, PieChart, Sector } from "recharts"

import {
  Card,
  CardContent,
  CardDescription,
  CardHeader,
  CardTitle,
} from "@/components/ui/card"
import {
  type ChartConfig,
  ChartContainer,
  ChartTooltip,
  ChartTooltipContent,
} from "@/components/ui/chart"

const chartData = [
  { device: "phone", users: 275, fill: "var(--color-phone)" },
  { device: "laptop", users: 200, fill: "var(--color-laptop)" },
  { device: "tablet", users: 187, fill: "var(--color-tablet)" },
  { device: "watch", users: 173, fill: "var(--color-watch)" },
  { device: "other", users: 90, fill: "var(--color-other)" },
]

const chartConfig = {
  users: { label: "Users" },
  phone: { label: "Phone", color: "var(--chart-1)" },
  laptop: { label: "Laptop", color: "var(--chart-2)" },
  tablet: { label: "Tablet", color: "var(--chart-3)" },
  watch: { label: "Watch", color: "var(--chart-4)" },
  other: { label: "Other", color: "var(--chart-5)" },
} satisfies ChartConfig

const ACTIVE = 0

export function PieChartActive() {
  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>Highlighted slice</CardTitle>
        <CardDescription>The selected slice pops out</CardDescription>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          className="aspect-auto h-52 w-full"
        >
          <PieChart accessibilityLayer>
            <ChartTooltip
              cursor={false}
              content={<ChartTooltipContent hideLabel nameKey="device" />}
            />
            <Pie
              data={chartData}
              dataKey="users"
              nameKey="device"
              innerRadius="50%"
              outerRadius="78%"
              strokeWidth={0}
              shape={(props, index) =>
                index === ACTIVE ? (
                  <g>
                    <Sector
                      {...props}
                      outerRadius={(props.outerRadius ?? 0) + 10}
                    />
                    <Sector
                      {...props}
                      innerRadius={(props.outerRadius ?? 0) + 13}
                      outerRadius={(props.outerRadius ?? 0) + 16}
                    />
                  </g>
                ) : (
                  <Sector {...props} />
                )
              }
            />
          </PieChart>
        </ChartContainer>
      </CardContent>
    </Card>
  )
}
```

A donut with one slice pulled outward and traced by a thin outer arc, so a single category stands out from the rest. Use it to call attention to the segment a page is about, such as the current plan or the user's own device.

Give each record in `chartData` a value and a `fill` that points at its color in `chartConfig`. Set `ACTIVE` to the index of the slice to emphasize; the highlight does not follow hover, so drive `ACTIVE` from state if it should follow a selection.

### Installation

**Command**

```bash title="Terminal"
npx shadcn@latest add @esuiss/pie-chart-active
```

Works in any project with a `components.json`. See [Installation](https://suiss.app/ui/docs/installation#add-components) for the one-line registry setup. Or use the [suiss/ui CLI](https://suiss.app/ui/docs/cli):

```bash title="Terminal"
npx @esuiss/ui@latest add charts pie-chart-active
```

**Manual**

1. Install the following dependencies:

```bash title="Terminal"
npm install recharts
```

2. Add the pieces it builds on: [Card](https://suiss.app/ui/docs/components/card), [Chart](https://suiss.app/ui/docs/components/chart).

3. Copy and paste the following code into your project.

```tsx title="components/charts/pie-chart-active.tsx"
"use client"

import { Pie, PieChart, Sector } from "recharts"

import {
  Card,
  CardContent,
  CardDescription,
  CardHeader,
  CardTitle,
} from "@/components/ui/card"
import {
  type ChartConfig,
  ChartContainer,
  ChartTooltip,
  ChartTooltipContent,
} from "@/components/ui/chart"

const chartData = [
  { device: "phone", users: 275, fill: "var(--color-phone)" },
  { device: "laptop", users: 200, fill: "var(--color-laptop)" },
  { device: "tablet", users: 187, fill: "var(--color-tablet)" },
  { device: "watch", users: 173, fill: "var(--color-watch)" },
  { device: "other", users: 90, fill: "var(--color-other)" },
]

const chartConfig = {
  users: { label: "Users" },
  phone: { label: "Phone", color: "var(--chart-1)" },
  laptop: { label: "Laptop", color: "var(--chart-2)" },
  tablet: { label: "Tablet", color: "var(--chart-3)" },
  watch: { label: "Watch", color: "var(--chart-4)" },
  other: { label: "Other", color: "var(--chart-5)" },
} satisfies ChartConfig

const ACTIVE = 0

export function PieChartActive() {
  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>Highlighted slice</CardTitle>
        <CardDescription>The selected slice pops out</CardDescription>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          className="aspect-auto h-52 w-full"
        >
          <PieChart accessibilityLayer>
            <ChartTooltip
              cursor={false}
              content={<ChartTooltipContent hideLabel nameKey="device" />}
            />
            <Pie
              data={chartData}
              dataKey="users"
              nameKey="device"
              innerRadius="50%"
              outerRadius="78%"
              strokeWidth={0}
              shape={(props, index) =>
                index === ACTIVE ? (
                  <g>
                    <Sector
                      {...props}
                      outerRadius={(props.outerRadius ?? 0) + 10}
                    />
                    <Sector
                      {...props}
                      innerRadius={(props.outerRadius ?? 0) + 13}
                      outerRadius={(props.outerRadius ?? 0) + 16}
                    />
                  </g>
                ) : (
                  <Sector {...props} />
                )
              }
            />
          </PieChart>
        </ChartContainer>
      </CardContent>
    </Card>
  )
}
```

4. Update the import paths to match your project setup.

### Usage

```tsx
import { PieChartActive } from "@/components/charts/pie-chart-active"
```

```tsx
<PieChartActive />
```

**React Native, SwiftUI, Jetpack Compose**

```tsx title="uniwind/components/charts/pie-chart-active.tsx"
import {
  Card,
  CardContent,
  CardDescription,
  CardHeader,
  CardTitle,
} from "@/components/ui/card"
import {
  type ChartConfig,
  ChartContainer,
  ChartTooltip,
  ChartTooltipContent,
  Pie,
  PieChart,
} from "@/components/ui/chart"

const chartData = [
  { device: "phone", users: 275 },
  { device: "laptop", users: 200 },
  { device: "tablet", users: 187 },
  { device: "watch", users: 173 },
  { device: "other", users: 90 },
]

const chartConfig = {
  users: { label: "Users" },
  phone: { label: "Phone", color: "chart-1" },
  laptop: { label: "Laptop", color: "chart-2" },
  tablet: { label: "Tablet", color: "chart-3" },
  watch: { label: "Watch", color: "chart-4" },
  other: { label: "Other", color: "chart-5" },
} satisfies ChartConfig

const ACTIVE = 0

export function PieChartActive() {
  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>Highlighted slice</CardTitle>
        <CardDescription>The selected slice pops out</CardDescription>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          accessibilityLabel="Highlighted slice"
          className="h-52 w-full"
        >
          <PieChart>
            <ChartTooltip
              cursor={false}
              content={<ChartTooltipContent hideLabel nameKey="device" />}
            />
            <Pie
              data={chartData}
              dataKey="users"
              nameKey="device"
              innerRadius="50%"
              outerRadius="78%"
              strokeWidth={0}
              shape={(sector, index) =>
                index === ACTIVE
                  ? [
                      { ...sector, outerRadius: sector.outerRadius + 10 },
                      {
                        ...sector,
                        innerRadius: sector.outerRadius + 13,
                        outerRadius: sector.outerRadius + 16,
                      },
                    ]
                  : sector
              }
            />
          </PieChart>
        </ChartContainer>
      </CardContent>
    </Card>
  )
}
```

```swift title="swift/Charts/PieChartActive.swift"
import Charts
import SwiftUI

private let chartData: [(device: String, users: Double)] = [
  ("phone", 275), ("laptop", 200), ("tablet", 187), ("watch", 173), ("other", 90),
]

private let chartConfig: ChartConfig = [
  "users": .init("Users"),
  "phone": .init("Phone", color: EsuissColor.chart1),
  "laptop": .init("Laptop", color: EsuissColor.chart2),
  "tablet": .init("Tablet", color: EsuissColor.chart3),
  "watch": .init("Watch", color: EsuissColor.chart4),
  "other": .init("Other", color: EsuissColor.chart5),
]

private let total = chartData.reduce(0) { $0 + $1.users }

public struct PieChartActive: View {
  @State private var selected = 0
  @Environment(\.accessibilityReduceMotion) private var reduceMotion

  public init() {}

  private var selection: Binding<Int?> {
    Binding(get: { selected }, set: { if let value = $0 { selected = value } })
  }

  public var body: some View {
    Card(.filled, size: .sm) {
      CardHeader("Highlighted slice", description: "The selected slice pops out")
      CardContent {
        ChartContainer(config: chartConfig) {
          ChartAnimator { progress in
            ZStack {
              GeometryReader { geometry in
                let radius = min(geometry.size.width, geometry.size.height) / 2
                let before = chartData.prefix(selected).reduce(0) { $0 + $1.users }
                ChartArc(
                  center: CGPoint(x: geometry.size.width / 2, y: geometry.size.height / 2),
                  radius: radius * 0.92,
                  thickness: radius * 0.029,
                  start: .degrees(before / total * 360 * progress),
                  end: .degrees((before + chartData[selected].users) / total * 360 * progress),
                  rounded: false
                )
                .fill(chartConfig.color(chartData[selected].device))
              }
              .accessibilityHidden(true)
              Chart {
                ForEach(chartData.indices, id: \.self) { index in
                  SectorMark(
                    angle: .value("Users", chartData[index].users * progress),
                    innerRadius: .ratio(0.5),
                    outerRadius: .ratio(index == selected ? 0.876 : 0.78)
                  )
                  .foregroundStyle(chartConfig.color(chartData[index].device))
                }
                ChartSectorRest(total: total, progress: progress)
              }
              .chartTooltip(
                angle: chartData.map(\.users),
                labels: chartData.map { chartConfig.label($0.device) },
                innerRadius: 0.5,
                outerRadius: 0.876,
                selection: selection,
                accessibilityLabel: "Highlighted slice",
                items: { [ChartTooltipItem(chartData[$0].device, value: chartData[$0].users)] }
              ) { payload in
                ChartTooltipContent(payload, hideLabel: true)
              }
            }
            .animation(reduceMotion ? nil : .easeOut(duration: 0.2), value: selected)
            .padding(5)
          }
        }
        .frame(height: 208)
      }
    }
  }
}
```

```kt title="kotlin/charts/PieChartActive.kt"
package com.esuiss.ui.charts

import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.esuiss.ui.components.Card
import com.esuiss.ui.components.CardContent
import com.esuiss.ui.components.CardHeader
import com.esuiss.ui.components.CardSize
import com.esuiss.ui.components.CardVariant
import com.esuiss.ui.components.ChartConfig
import com.esuiss.ui.components.ChartConfigItem
import com.esuiss.ui.components.ChartContainer
import com.esuiss.ui.components.ChartTooltipContent
import com.esuiss.ui.components.PieChart
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import com.esuiss.ui.components.ChartRing
import com.esuiss.ui.components.ChartSector

private class PieActiveDeviceUsers(val device: String, val users: Double)

private val chartData = listOf(
    PieActiveDeviceUsers("phone", 275.0),
    PieActiveDeviceUsers("laptop", 200.0),
    PieActiveDeviceUsers("tablet", 187.0),
    PieActiveDeviceUsers("watch", 173.0),
    PieActiveDeviceUsers("other", 90.0),
)

private val chartConfig = ChartConfig(
    "users" to ChartConfigItem("Users"),
    "phone" to ChartConfigItem("Phone") { chart1 },
    "laptop" to ChartConfigItem("Laptop") { chart2 },
    "tablet" to ChartConfigItem("Tablet") { chart3 },
    "watch" to ChartConfigItem("Watch") { chart4 },
    "other" to ChartConfigItem("Other") { chart5 },
)

@Composable
fun PieChartActive(modifier: Modifier = Modifier) {
    var selected by remember { mutableIntStateOf(0) }
    Card(modifier, variant = CardVariant.Filled, size = CardSize.Sm) {
        CardHeader("Highlighted slice", description = "The selected slice pops out")
        CardContent {
            ChartContainer(
                chartConfig,
                Modifier
                    .fillMaxWidth()
                    .height(208.dp),
            ) {
                PieChart(
                    accessibilityLabel = "Highlighted slice",
                    selectedIndex = selected,
                    onSelectedIndexChange = { index -> if (index != null) selected = index },
                ) {
                    ChartTooltip { ChartTooltipContent(hideLabel = true) }
                    Pie(
                        chartData,
                        value = { it.users },
                        nameKey = { it.device },
                        innerRadius = 0.5f,
                        outerRadius = 0.78f,
                        strokeWidth = 0.dp,
                        sectors = { index -> if (index == selected) ChartSector(10.dp, ChartRing(3.dp, 3.dp)) else ChartSector() },
                    )
                }
            }
        }
    }
}
```

**React Native**

A `PieChart` donut inside a `Card`, showing users by device. `chartData` holds one record per device with a `users` count. The `Pie` `shape` callback enlarges the slice at index `ACTIVE` and adds a thin arc outside it. Pressing a slice shows a tooltip with its name and value.

Replace `chartData` with your records and keep `dataKey` and `nameKey` in step with your field names. Add one entry per slice to `chartConfig` with its label and color; change `ACTIVE` to highlight a different slice. The component takes no props.

**React Native, SwiftUI, Jetpack Compose**

### Installation

**Command**

**React Native**

```bash title="Terminal"
npx shadcn@latest add @esuiss/pie-chart-active
```

See [Installation](https://suiss.app/ui/docs/installation) for the `components.json` setup. Or use the [suiss/ui CLI](https://suiss.app/ui/docs/cli):

```bash title="Terminal"
npx @esuiss/ui@latest add charts pie-chart-active
```

**SwiftUI**

```bash title="Terminal"
npx shadcn@latest add @esuiss/pie-chart-active
```

See [Installation](https://suiss.app/ui/docs/installation) for the `components.json` setup. Or use the [suiss/ui CLI](https://suiss.app/ui/docs/cli):

```bash title="Terminal"
npx @esuiss/ui@latest add charts pie-chart-active --platform swift
```

**Jetpack Compose**

```bash title="Terminal"
npx shadcn@latest add @esuiss/pie-chart-active
```

See [Installation](https://suiss.app/ui/docs/installation) for the `components.json` setup. Or use the [suiss/ui CLI](https://suiss.app/ui/docs/cli):

```bash title="Terminal"
npx @esuiss/ui@latest add charts pie-chart-active --platform kotlin
```

**React Native**

The CLI also adds what it builds on: [Card](https://suiss.app/ui/docs/components/card), [Chart](https://suiss.app/ui/docs/components/chart).

**React Native, SwiftUI, Jetpack Compose**

**Manual**

**React Native**

**Uniwind**

1. Add the pieces it builds on: [Card](https://suiss.app/ui/docs/components/card), [Chart](https://suiss.app/ui/docs/components/chart).

2. Copy and paste the following code into `components/charts/pie-chart-active.tsx`:

- `uniwind/components/charts/pie-chart-active.tsx`: shown above

3. Update the import paths to match your project setup.

**NativeWind**

1. Add the pieces it builds on: [Card](https://suiss.app/ui/docs/components/card), [Chart](https://suiss.app/ui/docs/components/chart).

2. Copy and paste the following code into `components/charts/pie-chart-active.tsx`:

```tsx title="nativewind/components/charts/pie-chart-active.tsx"
import {
  Card,
  CardContent,
  CardDescription,
  CardHeader,
  CardTitle,
} from "@/components/ui/card"
import {
  type ChartConfig,
  ChartContainer,
  ChartTooltip,
  ChartTooltipContent,
  Pie,
  PieChart,
} from "@/components/ui/chart"

const chartData = [
  { device: "phone", users: 275 },
  { device: "laptop", users: 200 },
  { device: "tablet", users: 187 },
  { device: "watch", users: 173 },
  { device: "other", users: 90 },
]

const chartConfig = {
  users: { label: "Users" },
  phone: { label: "Phone", color: "chart-1" },
  laptop: { label: "Laptop", color: "chart-2" },
  tablet: { label: "Tablet", color: "chart-3" },
  watch: { label: "Watch", color: "chart-4" },
  other: { label: "Other", color: "chart-5" },
} satisfies ChartConfig

const ACTIVE = 0

export function PieChartActive() {
  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>Highlighted slice</CardTitle>
        <CardDescription>The selected slice pops out</CardDescription>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          accessibilityLabel="Highlighted slice"
          className="h-52 w-full"
        >
          <PieChart>
            <ChartTooltip
              cursor={false}
              content={<ChartTooltipContent hideLabel nameKey="device" />}
            />
            <Pie
              data={chartData}
              dataKey="users"
              nameKey="device"
              innerRadius="50%"
              outerRadius="78%"
              strokeWidth={0}
              shape={(sector, index) =>
                index === ACTIVE
                  ? [
                      { ...sector, outerRadius: sector.outerRadius + 10 },
                      {
                        ...sector,
                        innerRadius: sector.outerRadius + 13,
                        outerRadius: sector.outerRadius + 16,
                      },
                    ]
                  : sector
              }
            />
          </PieChart>
        </ChartContainer>
      </CardContent>
    </Card>
  )
}
```

3. Update the import paths to match your project setup.

**StyleSheet**

1. Add the pieces it builds on: [Card](https://suiss.app/ui/docs/components/card), [Chart](https://suiss.app/ui/docs/components/chart).

2. Copy and paste the following code into `components/charts/pie-chart-active.tsx`:

```tsx title="stylesheet/components/charts/pie-chart-active.tsx"
import {
  Card,
  CardContent,
  CardDescription,
  CardHeader,
  CardTitle,
} from "@/components/ui/card"
import {
  type ChartConfig,
  ChartContainer,
  ChartTooltip,
  ChartTooltipContent,
  Pie,
  PieChart,
} from "@/components/ui/chart"

const chartData = [
  { device: "phone", users: 275 },
  { device: "laptop", users: 200 },
  { device: "tablet", users: 187 },
  { device: "watch", users: 173 },
  { device: "other", users: 90 },
]

const chartConfig = {
  users: { label: "Users" },
  phone: { label: "Phone", color: "chart-1" },
  laptop: { label: "Laptop", color: "chart-2" },
  tablet: { label: "Tablet", color: "chart-3" },
  watch: { label: "Watch", color: "chart-4" },
  other: { label: "Other", color: "chart-5" },
} satisfies ChartConfig

const ACTIVE = 0

export function PieChartActive() {
  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>Highlighted slice</CardTitle>
        <CardDescription>The selected slice pops out</CardDescription>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          accessibilityLabel="Highlighted slice"
          style={{ height: 208 }}
        >
          <PieChart>
            <ChartTooltip
              cursor={false}
              content={<ChartTooltipContent hideLabel nameKey="device" />}
            />
            <Pie
              data={chartData}
              dataKey="users"
              nameKey="device"
              innerRadius="50%"
              outerRadius="78%"
              strokeWidth={0}
              shape={(sector, index) =>
                index === ACTIVE
                  ? [
                      { ...sector, outerRadius: sector.outerRadius + 10 },
                      {
                        ...sector,
                        innerRadius: sector.outerRadius + 13,
                        outerRadius: sector.outerRadius + 16,
                      },
                    ]
                  : sector
              }
            />
          </PieChart>
        </ChartContainer>
      </CardContent>
    </Card>
  )
}
```

3. Update the import paths to match your project setup.

**SwiftUI**

1. Target iOS 17 or later.

2. Copy the theme files every view uses:

- `swift/Theme/Theme.swift`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/swiftui/Sources/EsuissUI/Theme/Theme.swift)

- `swift/Theme/Tokens.swift`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/swiftui/Sources/EsuissUI/Theme/Tokens.swift)

3. Copy the source and every file it uses:

- `swift/Charts/PieChartActive.swift`: shown above

- `swift/Components/Card.swift`: see [Card](https://suiss.app/ui/docs/components/card.md)

- `swift/Components/Chart.swift`: see [Chart](https://suiss.app/ui/docs/components/chart.md)

- `swift/Components/Haptics.swift`: see [Haptics](https://suiss.app/ui/docs/components/haptics.md)

- `swift/Components/Item.swift`: see [Item](https://suiss.app/ui/docs/components/item.md)

- `swift/Components/Separator.swift`: see [Separator](https://suiss.app/ui/docs/components/separator.md)

4. Add the files to your app target.

**Jetpack Compose**

1. Apply the Compose compiler plugin, enable Compose, set `compileSdk` to 37 or higher and `minSdk` to 24 or higher, and add the dependencies:

```kotlin title="build.gradle.kts"
plugins {
    id("org.jetbrains.kotlin.plugin.compose")
}

android {
    compileSdk = 37
    defaultConfig { minSdk = 24 }
    buildFeatures { compose = true }
}

dependencies {
    implementation(platform("androidx.compose:compose-bom:2026.09.00"))
    implementation("androidx.compose.foundation:foundation")
    implementation("androidx.compose.ui:ui")
}
```

2. Copy the theme files every view uses:

- `kotlin/theme/Theme.kt`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/kotlin/ui/src/main/kotlin/com/esuiss/ui/theme/Theme.kt)

- `kotlin/theme/Tokens.kt`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/kotlin/ui/src/main/kotlin/com/esuiss/ui/theme/Tokens.kt)

3. Copy the source and every file it uses:

- `kotlin/charts/PieChartActive.kt`: shown above

- `kotlin/components/Card.kt`: see [Card](https://suiss.app/ui/docs/components/card.md)

- `kotlin/components/Chart.kt`: see [Chart](https://suiss.app/ui/docs/components/chart.md)

- `kotlin/components/Content.kt`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/kotlin/ui/src/main/kotlin/com/esuiss/ui/components/Content.kt)

- `kotlin/components/FormSupport.kt`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/kotlin/ui/src/main/kotlin/com/esuiss/ui/components/FormSupport.kt)

- `kotlin/components/Haptics.kt`: see [Haptics](https://suiss.app/ui/docs/components/haptics.md)

- `kotlin/components/Icon.kt`: see [Icon](https://suiss.app/ui/docs/components/icon.md)

4. Update the `com.esuiss.ui` package names to match your project.

**React Native, SwiftUI, Jetpack Compose**

### Usage

**React Native**

```tsx
import { PieChartActive } from "@/components/charts/pie-chart-active"
```

```tsx
<PieChartActive />
```

**SwiftUI**

```swift
import SwiftUI

struct PieActiveExample: View {
  var body: some View {
    PieChartActive()
  }
}
```

**Jetpack Compose**

```kotlin
import androidx.compose.runtime.Composable
import com.esuiss.ui.charts.PieChartActive

@Composable
fun PieActiveExample() {
    PieChartActive()
}
```



## Pie Chart Donut Text

A donut with the total number of users displayed in the center of the ring.

Source: https://suiss.app/ui/docs/charts/pie-chart#donut-text

**React**

**Example**

```tsx title="components/charts/pie-chart-donut-text.tsx"
"use client"

import { Pie, PieChart } from "recharts"

import {
  Card,
  CardContent,
  CardDescription,
  CardHeader,
  CardTitle,
} from "@/components/ui/card"
import {
  type ChartConfig,
  ChartContainer,
  ChartTooltip,
  ChartTooltipContent,
} from "@/components/ui/chart"

const chartData = [
  { device: "phone", users: 275, fill: "var(--color-phone)" },
  { device: "laptop", users: 200, fill: "var(--color-laptop)" },
  { device: "tablet", users: 187, fill: "var(--color-tablet)" },
  { device: "watch", users: 173, fill: "var(--color-watch)" },
  { device: "other", users: 90, fill: "var(--color-other)" },
]

const chartConfig = {
  users: { label: "Users" },
  phone: { label: "Phone", color: "var(--chart-1)" },
  laptop: { label: "Laptop", color: "var(--chart-2)" },
  tablet: { label: "Tablet", color: "var(--chart-3)" },
  watch: { label: "Watch", color: "var(--chart-4)" },
  other: { label: "Other", color: "var(--chart-5)" },
} satisfies ChartConfig

const total = chartData.reduce((sum, item) => sum + item.users, 0)

export function PieChartDonutText() {
  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>Total in the middle</CardTitle>
        <CardDescription>A summary inside the ring</CardDescription>
      </CardHeader>
      <CardContent>
        <div className="relative">
          <ChartContainer
            config={chartConfig}
            className="aspect-auto h-52 w-full"
          >
            <PieChart accessibilityLayer>
              <ChartTooltip
                cursor={false}
                content={<ChartTooltipContent hideLabel nameKey="device" />}
              />
              <Pie
                data={chartData}
                dataKey="users"
                nameKey="device"
                innerRadius="62%"
                outerRadius="88%"
                strokeWidth={0}
                paddingAngle={1}
                cornerRadius={3}
              />
            </PieChart>
          </ChartContainer>
          <div className="pointer-events-none absolute inset-0 flex flex-col items-center justify-center text-center">
            <span className="text-2xl font-semibold tracking-tight tabular-nums">
              {total.toLocaleString("en-US")}
            </span>
            <span className="text-xs text-muted-foreground">users</span>
          </div>
        </div>
      </CardContent>
    </Card>
  )
}
```

A donut with the total shown in its center, so readers get the overall number and the breakdown in one glance. Prefer it over the plain donut when the total is the headline.

Replace `chartData` and the category entries in `chartConfig`; the center total is summed from the data. Change the caption under the number to your unit, and adjust `innerRadius` if a longer number needs more room. The center text lets pointer events through, so slice tooltips still work.

### Installation

**Command**

```bash title="Terminal"
npx shadcn@latest add @esuiss/pie-chart-donut-text
```

Works in any project with a `components.json`. See [Installation](https://suiss.app/ui/docs/installation#add-components) for the one-line registry setup. Or use the [suiss/ui CLI](https://suiss.app/ui/docs/cli):

```bash title="Terminal"
npx @esuiss/ui@latest add charts pie-chart-donut-text
```

**Manual**

1. Install the following dependencies:

```bash title="Terminal"
npm install recharts
```

2. Add the pieces it builds on: [Card](https://suiss.app/ui/docs/components/card), [Chart](https://suiss.app/ui/docs/components/chart).

3. Copy and paste the following code into your project.

```tsx title="components/charts/pie-chart-donut-text.tsx"
"use client"

import { Pie, PieChart } from "recharts"

import {
  Card,
  CardContent,
  CardDescription,
  CardHeader,
  CardTitle,
} from "@/components/ui/card"
import {
  type ChartConfig,
  ChartContainer,
  ChartTooltip,
  ChartTooltipContent,
} from "@/components/ui/chart"

const chartData = [
  { device: "phone", users: 275, fill: "var(--color-phone)" },
  { device: "laptop", users: 200, fill: "var(--color-laptop)" },
  { device: "tablet", users: 187, fill: "var(--color-tablet)" },
  { device: "watch", users: 173, fill: "var(--color-watch)" },
  { device: "other", users: 90, fill: "var(--color-other)" },
]

const chartConfig = {
  users: { label: "Users" },
  phone: { label: "Phone", color: "var(--chart-1)" },
  laptop: { label: "Laptop", color: "var(--chart-2)" },
  tablet: { label: "Tablet", color: "var(--chart-3)" },
  watch: { label: "Watch", color: "var(--chart-4)" },
  other: { label: "Other", color: "var(--chart-5)" },
} satisfies ChartConfig

const total = chartData.reduce((sum, item) => sum + item.users, 0)

export function PieChartDonutText() {
  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>Total in the middle</CardTitle>
        <CardDescription>A summary inside the ring</CardDescription>
      </CardHeader>
      <CardContent>
        <div className="relative">
          <ChartContainer
            config={chartConfig}
            className="aspect-auto h-52 w-full"
          >
            <PieChart accessibilityLayer>
              <ChartTooltip
                cursor={false}
                content={<ChartTooltipContent hideLabel nameKey="device" />}
              />
              <Pie
                data={chartData}
                dataKey="users"
                nameKey="device"
                innerRadius="62%"
                outerRadius="88%"
                strokeWidth={0}
                paddingAngle={1}
                cornerRadius={3}
              />
            </PieChart>
          </ChartContainer>
          <div className="pointer-events-none absolute inset-0 flex flex-col items-center justify-center text-center">
            <span className="text-2xl font-semibold tracking-tight tabular-nums">
              {total.toLocaleString("en-US")}
            </span>
            <span className="text-xs text-muted-foreground">users</span>
          </div>
        </div>
      </CardContent>
    </Card>
  )
}
```

4. Update the import paths to match your project setup.

### Usage

```tsx
import { PieChartDonutText } from "@/components/charts/pie-chart-donut-text"
```

```tsx
<PieChartDonutText />
```

**React Native, SwiftUI, Jetpack Compose**

```tsx title="uniwind/components/charts/pie-chart-donut-text.tsx"
import { View } from "react-native"
import {
  Card,
  CardContent,
  CardDescription,
  CardHeader,
  CardTitle,
} from "@/components/ui/card"
import {
  type ChartConfig,
  ChartContainer,
  ChartTooltip,
  ChartTooltipContent,
  Pie,
  PieChart,
} from "@/components/ui/chart"
import { Text } from "@/components/ui/text"

const chartData = [
  { device: "phone", users: 275 },
  { device: "laptop", users: 200 },
  { device: "tablet", users: 187 },
  { device: "watch", users: 173 },
  { device: "other", users: 90 },
]

const chartConfig = {
  users: { label: "Users" },
  phone: { label: "Phone", color: "chart-1" },
  laptop: { label: "Laptop", color: "chart-2" },
  tablet: { label: "Tablet", color: "chart-3" },
  watch: { label: "Watch", color: "chart-4" },
  other: { label: "Other", color: "chart-5" },
} satisfies ChartConfig

const total = chartData.reduce((sum, item) => sum + item.users, 0)

function formatTotal(value: number) {
  try {
    return new Intl.NumberFormat("en-US").format(value)
  } catch {
    return String(value).replace(/\B(?=(\d{3})+(?!\d))/g, ",")
  }
}

export function PieChartDonutText() {
  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>Total in the middle</CardTitle>
        <CardDescription>A summary inside the ring</CardDescription>
      </CardHeader>
      <CardContent>
        <View>
          <View
            pointerEvents="none"
            className="absolute inset-0 items-center justify-center"
          >
            <Text className="text-2xl font-semibold tracking-tight tabular-nums">
              {formatTotal(total)}
            </Text>
            <Text className="text-xs text-muted-foreground">users</Text>
          </View>
          <ChartContainer
            config={chartConfig}
            accessibilityLabel="Total in the middle"
            className="h-52 w-full"
          >
            <PieChart>
              <ChartTooltip
                cursor={false}
                content={<ChartTooltipContent hideLabel nameKey="device" />}
              />
              <Pie
                data={chartData}
                dataKey="users"
                nameKey="device"
                innerRadius="62%"
                outerRadius="88%"
                strokeWidth={0}
                paddingAngle={1}
                cornerRadius={3}
              />
            </PieChart>
          </ChartContainer>
        </View>
      </CardContent>
    </Card>
  )
}
```

```swift title="swift/Charts/PieChartDonutText.swift"
import Charts
import SwiftUI

private let chartData: [(device: String, users: Double)] = [
  ("phone", 275), ("laptop", 200), ("tablet", 187), ("watch", 173), ("other", 90),
]

private let chartConfig: ChartConfig = [
  "users": .init("Users"),
  "phone": .init("Phone", color: EsuissColor.chart1),
  "laptop": .init("Laptop", color: EsuissColor.chart2),
  "tablet": .init("Tablet", color: EsuissColor.chart3),
  "watch": .init("Watch", color: EsuissColor.chart4),
  "other": .init("Other", color: EsuissColor.chart5),
]

private let total = chartData.reduce(0) { $0 + $1.users }

public struct PieChartDonutText: View {
  @State private var selection: Int?

  public init() {}

  public var body: some View {
    Card(.filled, size: .sm) {
      CardHeader("Total in the middle", description: "A summary inside the ring")
      CardContent {
        ChartContainer(config: chartConfig) {
          ChartAnimator { progress in
            Chart {
              ForEach(chartData, id: \.device) { item in
                SectorMark(angle: .value("Users", item.users * progress), innerRadius: .ratio(0.62), outerRadius: .ratio(0.88), angularInset: 0.75)
                  .cornerRadius(3)
                  .foregroundStyle(chartConfig.color(item.device))
              }
              ChartSectorRest(total: total, progress: progress)
            }
            .background {
              VStack(spacing: 0) {
                Text(total, format: .number)
                  .textStyle(.xl2, weight: .semibold)
                  .monospacedDigit()
                Text("users")
                  .textStyle(.xs)
                  .foregroundStyle(EsuissColor.mutedForeground)
              }
              .multilineTextAlignment(.center)
            }
            .chartTooltip(
              angle: chartData.map(\.users),
              labels: chartData.map { chartConfig.label($0.device) },
              innerRadius: 0.62,
              outerRadius: 0.88,
              selection: $selection,
              accessibilityLabel: "Total in the middle",
              items: { [ChartTooltipItem(chartData[$0].device, value: chartData[$0].users)] }
            ) { payload in
              ChartTooltipContent(payload, hideLabel: true)
            }
            .padding(5)
          }
        }
        .frame(height: 208)
      }
    }
  }
}
```

```kt title="kotlin/charts/PieChartDonutText.kt"
package com.esuiss.ui.charts

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.text.BasicText
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.semantics.clearAndSetSemantics
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import com.esuiss.ui.components.Card
import com.esuiss.ui.components.CardContent
import com.esuiss.ui.components.CardHeader
import com.esuiss.ui.components.CardSize
import com.esuiss.ui.components.CardVariant
import com.esuiss.ui.components.ChartConfig
import com.esuiss.ui.components.ChartConfigItem
import com.esuiss.ui.components.ChartContainer
import com.esuiss.ui.components.ChartTooltipContent
import com.esuiss.ui.components.PieChart
import com.esuiss.ui.theme.EsuissTheme
import com.esuiss.ui.theme.Typography
import java.text.NumberFormat
import java.util.Locale

private class PieDonutTextDeviceUsers(val device: String, val users: Double)

private val chartData = listOf(
    PieDonutTextDeviceUsers("phone", 275.0),
    PieDonutTextDeviceUsers("laptop", 200.0),
    PieDonutTextDeviceUsers("tablet", 187.0),
    PieDonutTextDeviceUsers("watch", 173.0),
    PieDonutTextDeviceUsers("other", 90.0),
)

private val chartConfig = ChartConfig(
    "users" to ChartConfigItem("Users"),
    "phone" to ChartConfigItem("Phone") { chart1 },
    "laptop" to ChartConfigItem("Laptop") { chart2 },
    "tablet" to ChartConfigItem("Tablet") { chart3 },
    "watch" to ChartConfigItem("Watch") { chart4 },
    "other" to ChartConfigItem("Other") { chart5 },
)

private val total = chartData.sumOf { it.users }

@Composable
fun PieChartDonutText(modifier: Modifier = Modifier) {
    val colors = EsuissTheme.colors
    Card(modifier, variant = CardVariant.Filled, size = CardSize.Sm) {
        CardHeader("Total in the middle", description = "A summary inside the ring")
        CardContent {
            Box(
                Modifier
                    .fillMaxWidth()
                    .height(208.dp),
            ) {
                ChartContainer(chartConfig, Modifier.matchParentSize()) {
                    PieChart(accessibilityLabel = "Total in the middle, ${NumberFormat.getNumberInstance(Locale.US).format(total)} users") {
                        ChartTooltip { ChartTooltipContent(hideLabel = true) }
                        Pie(
                            chartData,
                            value = { it.users },
                            nameKey = { it.device },
                            innerRadius = 0.62f,
                            outerRadius = 0.88f,
                            strokeWidth = 0.dp,
                            paddingAngle = 1f,
                            cornerRadius = 3.dp,
                        )
                    }
                }
                Column(
                    Modifier
                        .align(Alignment.Center)
                        .clearAndSetSemantics {},
                    horizontalAlignment = Alignment.CenterHorizontally,
                ) {
                    BasicText(
                        NumberFormat.getNumberInstance(Locale.US).format(total),
                        style = Typography.xl2.copy(color = colors.foreground, fontWeight = FontWeight.SemiBold, fontFeatureSettings = "tnum"),
                    )
                    BasicText("users", style = Typography.xs.copy(color = colors.mutedForeground))
                }
            }
        }
    }
}
```

**React Native**

A `PieChart` donut with small gaps and rounded slice corners. `chartData` holds one record per device with a `users` count. The total is summed from `chartData` and drawn as `Text` layered over the ring. Pressing a slice shows a tooltip.

Replace `chartData` with your records; the center total recalculates from it. Update the `users` caption and `chartConfig` labels and colors to match. The component takes no props.

**React Native, SwiftUI, Jetpack Compose**

### Installation

**Command**

**React Native**

```bash title="Terminal"
npx shadcn@latest add @esuiss/pie-chart-donut-text
```

See [Installation](https://suiss.app/ui/docs/installation) for the `components.json` setup. Or use the [suiss/ui CLI](https://suiss.app/ui/docs/cli):

```bash title="Terminal"
npx @esuiss/ui@latest add charts pie-chart-donut-text
```

**SwiftUI**

```bash title="Terminal"
npx shadcn@latest add @esuiss/pie-chart-donut-text
```

See [Installation](https://suiss.app/ui/docs/installation) for the `components.json` setup. Or use the [suiss/ui CLI](https://suiss.app/ui/docs/cli):

```bash title="Terminal"
npx @esuiss/ui@latest add charts pie-chart-donut-text --platform swift
```

**Jetpack Compose**

```bash title="Terminal"
npx shadcn@latest add @esuiss/pie-chart-donut-text
```

See [Installation](https://suiss.app/ui/docs/installation) for the `components.json` setup. Or use the [suiss/ui CLI](https://suiss.app/ui/docs/cli):

```bash title="Terminal"
npx @esuiss/ui@latest add charts pie-chart-donut-text --platform kotlin
```

**React Native**

The CLI also adds what it builds on: [Card](https://suiss.app/ui/docs/components/card), [Chart](https://suiss.app/ui/docs/components/chart), [Text](https://suiss.app/ui/docs/components/text).

**React Native, SwiftUI, Jetpack Compose**

**Manual**

**React Native**

**Uniwind**

1. Add the pieces it builds on: [Card](https://suiss.app/ui/docs/components/card), [Chart](https://suiss.app/ui/docs/components/chart), [Text](https://suiss.app/ui/docs/components/text).

2. Copy and paste the following code into `components/charts/pie-chart-donut-text.tsx`:

- `uniwind/components/charts/pie-chart-donut-text.tsx`: shown above

3. Update the import paths to match your project setup.

**NativeWind**

1. Add the pieces it builds on: [Card](https://suiss.app/ui/docs/components/card), [Chart](https://suiss.app/ui/docs/components/chart), [Text](https://suiss.app/ui/docs/components/text).

2. Copy and paste the following code into `components/charts/pie-chart-donut-text.tsx`:

```tsx title="nativewind/components/charts/pie-chart-donut-text.tsx"
import { View } from "react-native"
import {
  Card,
  CardContent,
  CardDescription,
  CardHeader,
  CardTitle,
} from "@/components/ui/card"
import {
  type ChartConfig,
  ChartContainer,
  ChartTooltip,
  ChartTooltipContent,
  Pie,
  PieChart,
} from "@/components/ui/chart"
import { Text } from "@/components/ui/text"

const chartData = [
  { device: "phone", users: 275 },
  { device: "laptop", users: 200 },
  { device: "tablet", users: 187 },
  { device: "watch", users: 173 },
  { device: "other", users: 90 },
]

const chartConfig = {
  users: { label: "Users" },
  phone: { label: "Phone", color: "chart-1" },
  laptop: { label: "Laptop", color: "chart-2" },
  tablet: { label: "Tablet", color: "chart-3" },
  watch: { label: "Watch", color: "chart-4" },
  other: { label: "Other", color: "chart-5" },
} satisfies ChartConfig

const total = chartData.reduce((sum, item) => sum + item.users, 0)

function formatTotal(value: number) {
  try {
    return new Intl.NumberFormat("en-US").format(value)
  } catch {
    return String(value).replace(/\B(?=(\d{3})+(?!\d))/g, ",")
  }
}

export function PieChartDonutText() {
  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>Total in the middle</CardTitle>
        <CardDescription>A summary inside the ring</CardDescription>
      </CardHeader>
      <CardContent>
        <View>
          <View
            pointerEvents="none"
            className="absolute inset-0 items-center justify-center"
          >
            <Text className="text-2xl font-semibold tracking-tight tabular-nums">
              {formatTotal(total)}
            </Text>
            <Text className="text-xs text-muted-foreground">users</Text>
          </View>
          <ChartContainer
            config={chartConfig}
            accessibilityLabel="Total in the middle"
            className="h-52 w-full"
          >
            <PieChart>
              <ChartTooltip
                cursor={false}
                content={<ChartTooltipContent hideLabel nameKey="device" />}
              />
              <Pie
                data={chartData}
                dataKey="users"
                nameKey="device"
                innerRadius="62%"
                outerRadius="88%"
                strokeWidth={0}
                paddingAngle={1}
                cornerRadius={3}
              />
            </PieChart>
          </ChartContainer>
        </View>
      </CardContent>
    </Card>
  )
}
```

3. Update the import paths to match your project setup.

**StyleSheet**

1. Add the pieces it builds on: [Card](https://suiss.app/ui/docs/components/card), [Chart](https://suiss.app/ui/docs/components/chart), [Text](https://suiss.app/ui/docs/components/text).

2. Copy and paste the following code into `components/charts/pie-chart-donut-text.tsx`:

```tsx title="stylesheet/components/charts/pie-chart-donut-text.tsx"
import { StyleSheet, View } from "react-native"
import {
  Card,
  CardContent,
  CardDescription,
  CardHeader,
  CardTitle,
} from "@/components/ui/card"
import {
  type ChartConfig,
  ChartContainer,
  ChartTooltip,
  ChartTooltipContent,
  Pie,
  PieChart,
} from "@/components/ui/chart"
import { Text } from "@/components/ui/text"
import { fontSize, useTheme } from "@/components/ui/theme"

const chartData = [
  { device: "phone", users: 275 },
  { device: "laptop", users: 200 },
  { device: "tablet", users: 187 },
  { device: "watch", users: 173 },
  { device: "other", users: 90 },
]

const chartConfig = {
  users: { label: "Users" },
  phone: { label: "Phone", color: "chart-1" },
  laptop: { label: "Laptop", color: "chart-2" },
  tablet: { label: "Tablet", color: "chart-3" },
  watch: { label: "Watch", color: "chart-4" },
  other: { label: "Other", color: "chart-5" },
} satisfies ChartConfig

const total = chartData.reduce((sum, item) => sum + item.users, 0)

function formatTotal(value: number) {
  try {
    return new Intl.NumberFormat("en-US").format(value)
  } catch {
    return String(value).replace(/\B(?=(\d{3})+(?!\d))/g, ",")
  }
}

const styles = StyleSheet.create({
  overlay: {
    ...StyleSheet.absoluteFill,
    alignItems: "center",
    justifyContent: "center",
  },
  value: {
    ...fontSize["2xl"],
    fontWeight: "600",
    letterSpacing: -0.7,
    fontVariant: ["tabular-nums"],
  },
  caption: { ...fontSize.xs },
  chart: { height: 208 },
})

export function PieChartDonutText() {
  const { colors } = useTheme()
  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>Total in the middle</CardTitle>
        <CardDescription>A summary inside the ring</CardDescription>
      </CardHeader>
      <CardContent>
        <View>
          <View pointerEvents="none" style={styles.overlay}>
            <Text style={styles.value}>{formatTotal(total)}</Text>
            <Text style={[styles.caption, { color: colors.mutedForeground }]}>
              users
            </Text>
          </View>
          <ChartContainer
            config={chartConfig}
            accessibilityLabel="Total in the middle"
            style={styles.chart}
          >
            <PieChart>
              <ChartTooltip
                cursor={false}
                content={<ChartTooltipContent hideLabel nameKey="device" />}
              />
              <Pie
                data={chartData}
                dataKey="users"
                nameKey="device"
                innerRadius="62%"
                outerRadius="88%"
                strokeWidth={0}
                paddingAngle={1}
                cornerRadius={3}
              />
            </PieChart>
          </ChartContainer>
        </View>
      </CardContent>
    </Card>
  )
}
```

3. Update the import paths to match your project setup.

**SwiftUI**

1. Target iOS 17 or later.

2. Copy the theme files every view uses:

- `swift/Theme/Theme.swift`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/swiftui/Sources/EsuissUI/Theme/Theme.swift)

- `swift/Theme/Tokens.swift`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/swiftui/Sources/EsuissUI/Theme/Tokens.swift)

3. Copy the source and every file it uses:

- `swift/Charts/PieChartDonutText.swift`: shown above

- `swift/Components/Card.swift`: see [Card](https://suiss.app/ui/docs/components/card.md)

- `swift/Components/Chart.swift`: see [Chart](https://suiss.app/ui/docs/components/chart.md)

- `swift/Components/Haptics.swift`: see [Haptics](https://suiss.app/ui/docs/components/haptics.md)

- `swift/Components/Item.swift`: see [Item](https://suiss.app/ui/docs/components/item.md)

- `swift/Components/Separator.swift`: see [Separator](https://suiss.app/ui/docs/components/separator.md)

4. Add the files to your app target.

**Jetpack Compose**

1. Apply the Compose compiler plugin, enable Compose, set `compileSdk` to 37 or higher and `minSdk` to 24 or higher, and add the dependencies:

```kotlin title="build.gradle.kts"
plugins {
    id("org.jetbrains.kotlin.plugin.compose")
}

android {
    compileSdk = 37
    defaultConfig { minSdk = 24 }
    buildFeatures { compose = true }
}

dependencies {
    implementation(platform("androidx.compose:compose-bom:2026.09.00"))
    implementation("androidx.compose.foundation:foundation")
    implementation("androidx.compose.ui:ui")
}
```

2. Copy the theme files every view uses:

- `kotlin/theme/Theme.kt`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/kotlin/ui/src/main/kotlin/com/esuiss/ui/theme/Theme.kt)

- `kotlin/theme/Tokens.kt`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/kotlin/ui/src/main/kotlin/com/esuiss/ui/theme/Tokens.kt)

3. Copy the source and every file it uses:

- `kotlin/charts/PieChartDonutText.kt`: shown above

- `kotlin/components/Card.kt`: see [Card](https://suiss.app/ui/docs/components/card.md)

- `kotlin/components/Chart.kt`: see [Chart](https://suiss.app/ui/docs/components/chart.md)

- `kotlin/components/Content.kt`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/kotlin/ui/src/main/kotlin/com/esuiss/ui/components/Content.kt)

- `kotlin/components/FormSupport.kt`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/kotlin/ui/src/main/kotlin/com/esuiss/ui/components/FormSupport.kt)

- `kotlin/components/Haptics.kt`: see [Haptics](https://suiss.app/ui/docs/components/haptics.md)

- `kotlin/components/Icon.kt`: see [Icon](https://suiss.app/ui/docs/components/icon.md)

4. Update the `com.esuiss.ui` package names to match your project.

**React Native, SwiftUI, Jetpack Compose**

### Usage

**React Native**

```tsx
import { PieChartDonutText } from "@/components/charts/pie-chart-donut-text"
```

```tsx
<PieChartDonutText />
```

**SwiftUI**

```swift
import SwiftUI

struct PieDonutTextExample: View {
  var body: some View {
    PieChartDonutText()
  }
}
```

**Jetpack Compose**

```kotlin
import androidx.compose.runtime.Composable
import com.esuiss.ui.charts.PieChartDonutText

@Composable
fun PieDonutTextExample() {
    PieChartDonutText()
}
```



## Pie Chart Donut

A donut chart with a hollow center and small gaps between slices.

Source: https://suiss.app/ui/docs/charts/pie-chart#donut

**React**

**Example**

```tsx title="components/charts/pie-chart-donut.tsx"
"use client"

import { Pie, PieChart } from "recharts"

import {
  Card,
  CardContent,
  CardDescription,
  CardHeader,
  CardTitle,
} from "@/components/ui/card"
import {
  type ChartConfig,
  ChartContainer,
  ChartTooltip,
  ChartTooltipContent,
} from "@/components/ui/chart"

const chartData = [
  { device: "phone", users: 275, fill: "var(--color-phone)" },
  { device: "laptop", users: 200, fill: "var(--color-laptop)" },
  { device: "tablet", users: 187, fill: "var(--color-tablet)" },
  { device: "watch", users: 173, fill: "var(--color-watch)" },
  { device: "other", users: 90, fill: "var(--color-other)" },
]

const chartConfig = {
  users: { label: "Users" },
  phone: { label: "Phone", color: "var(--chart-1)" },
  laptop: { label: "Laptop", color: "var(--chart-2)" },
  tablet: { label: "Tablet", color: "var(--chart-3)" },
  watch: { label: "Watch", color: "var(--chart-4)" },
  other: { label: "Other", color: "var(--chart-5)" },
} satisfies ChartConfig

export function PieChartDonut() {
  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>Donut</CardTitle>
        <CardDescription>A hole in the middle</CardDescription>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          className="aspect-auto h-52 w-full"
        >
          <PieChart accessibilityLayer>
            <ChartTooltip
              cursor={false}
              content={<ChartTooltipContent hideLabel nameKey="device" />}
            />
            <Pie
              data={chartData}
              dataKey="users"
              nameKey="device"
              innerRadius="58%"
              outerRadius="85%"
              strokeWidth={0}
              paddingAngle={1}
            />
          </PieChart>
        </ChartContainer>
      </CardContent>
    </Card>
  )
}
```

A donut with a hollow center and small gaps between slices. It reads lighter than a full pie and leaves the center free for a label if you need one later.

Replace `chartData` and add a label and color for each category key to `chartConfig`. `innerRadius` and `outerRadius` set the ring thickness, and `paddingAngle` the gap between slices.

### Installation

**Command**

```bash title="Terminal"
npx shadcn@latest add @esuiss/pie-chart-donut
```

Works in any project with a `components.json`. See [Installation](https://suiss.app/ui/docs/installation#add-components) for the one-line registry setup. Or use the [suiss/ui CLI](https://suiss.app/ui/docs/cli):

```bash title="Terminal"
npx @esuiss/ui@latest add charts pie-chart-donut
```

**Manual**

1. Install the following dependencies:

```bash title="Terminal"
npm install recharts
```

2. Add the pieces it builds on: [Card](https://suiss.app/ui/docs/components/card), [Chart](https://suiss.app/ui/docs/components/chart).

3. Copy and paste the following code into your project.

```tsx title="components/charts/pie-chart-donut.tsx"
"use client"

import { Pie, PieChart } from "recharts"

import {
  Card,
  CardContent,
  CardDescription,
  CardHeader,
  CardTitle,
} from "@/components/ui/card"
import {
  type ChartConfig,
  ChartContainer,
  ChartTooltip,
  ChartTooltipContent,
} from "@/components/ui/chart"

const chartData = [
  { device: "phone", users: 275, fill: "var(--color-phone)" },
  { device: "laptop", users: 200, fill: "var(--color-laptop)" },
  { device: "tablet", users: 187, fill: "var(--color-tablet)" },
  { device: "watch", users: 173, fill: "var(--color-watch)" },
  { device: "other", users: 90, fill: "var(--color-other)" },
]

const chartConfig = {
  users: { label: "Users" },
  phone: { label: "Phone", color: "var(--chart-1)" },
  laptop: { label: "Laptop", color: "var(--chart-2)" },
  tablet: { label: "Tablet", color: "var(--chart-3)" },
  watch: { label: "Watch", color: "var(--chart-4)" },
  other: { label: "Other", color: "var(--chart-5)" },
} satisfies ChartConfig

export function PieChartDonut() {
  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>Donut</CardTitle>
        <CardDescription>A hole in the middle</CardDescription>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          className="aspect-auto h-52 w-full"
        >
          <PieChart accessibilityLayer>
            <ChartTooltip
              cursor={false}
              content={<ChartTooltipContent hideLabel nameKey="device" />}
            />
            <Pie
              data={chartData}
              dataKey="users"
              nameKey="device"
              innerRadius="58%"
              outerRadius="85%"
              strokeWidth={0}
              paddingAngle={1}
            />
          </PieChart>
        </ChartContainer>
      </CardContent>
    </Card>
  )
}
```

4. Update the import paths to match your project setup.

### Usage

```tsx
import { PieChartDonut } from "@/components/charts/pie-chart-donut"
```

```tsx
<PieChartDonut />
```

**React Native, SwiftUI, Jetpack Compose**

```tsx title="uniwind/components/charts/pie-chart-donut.tsx"
import {
  Card,
  CardContent,
  CardDescription,
  CardHeader,
  CardTitle,
} from "@/components/ui/card"
import {
  type ChartConfig,
  ChartContainer,
  ChartTooltip,
  ChartTooltipContent,
  Pie,
  PieChart,
} from "@/components/ui/chart"

const chartData = [
  { device: "phone", users: 275 },
  { device: "laptop", users: 200 },
  { device: "tablet", users: 187 },
  { device: "watch", users: 173 },
  { device: "other", users: 90 },
]

const chartConfig = {
  users: { label: "Users" },
  phone: { label: "Phone", color: "chart-1" },
  laptop: { label: "Laptop", color: "chart-2" },
  tablet: { label: "Tablet", color: "chart-3" },
  watch: { label: "Watch", color: "chart-4" },
  other: { label: "Other", color: "chart-5" },
} satisfies ChartConfig

export function PieChartDonut() {
  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>Donut</CardTitle>
        <CardDescription>A hole in the middle</CardDescription>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          accessibilityLabel="Donut"
          className="h-52 w-full"
        >
          <PieChart>
            <ChartTooltip
              cursor={false}
              content={<ChartTooltipContent hideLabel nameKey="device" />}
            />
            <Pie
              data={chartData}
              dataKey="users"
              nameKey="device"
              innerRadius="58%"
              outerRadius="85%"
              strokeWidth={0}
              paddingAngle={1}
            />
          </PieChart>
        </ChartContainer>
      </CardContent>
    </Card>
  )
}
```

```swift title="swift/Charts/PieChartDonut.swift"
import Charts
import SwiftUI

private let chartData: [(device: String, users: Double)] = [
  ("phone", 275), ("laptop", 200), ("tablet", 187), ("watch", 173), ("other", 90),
]

private let chartConfig: ChartConfig = [
  "users": .init("Users"),
  "phone": .init("Phone", color: EsuissColor.chart1),
  "laptop": .init("Laptop", color: EsuissColor.chart2),
  "tablet": .init("Tablet", color: EsuissColor.chart3),
  "watch": .init("Watch", color: EsuissColor.chart4),
  "other": .init("Other", color: EsuissColor.chart5),
]

public struct PieChartDonut: View {
  @State private var selection: Int?

  public init() {}

  public var body: some View {
    Card(.filled, size: .sm) {
      CardHeader("Donut", description: "A hole in the middle")
      CardContent {
        ChartContainer(config: chartConfig) {
          ChartAnimator { progress in
            Chart {
              ForEach(chartData, id: \.device) { item in
                SectorMark(angle: .value("Users", item.users * progress), innerRadius: .ratio(0.58), outerRadius: .ratio(0.85), angularInset: 0.75)
                  .foregroundStyle(chartConfig.color(item.device))
              }
              ChartSectorRest(total: chartData.reduce(0) { $0 + $1.users }, progress: progress)
            }
            .chartTooltip(
              angle: chartData.map(\.users),
              labels: chartData.map { chartConfig.label($0.device) },
              innerRadius: 0.58,
              outerRadius: 0.85,
              selection: $selection,
              accessibilityLabel: "Donut",
              items: { [ChartTooltipItem(chartData[$0].device, value: chartData[$0].users)] }
            ) { payload in
              ChartTooltipContent(payload, hideLabel: true)
            }
            .padding(5)
          }
        }
        .frame(height: 208)
      }
    }
  }
}
```

```kt title="kotlin/charts/PieChartDonut.kt"
package com.esuiss.ui.charts

import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.esuiss.ui.components.Card
import com.esuiss.ui.components.CardContent
import com.esuiss.ui.components.CardHeader
import com.esuiss.ui.components.CardSize
import com.esuiss.ui.components.CardVariant
import com.esuiss.ui.components.ChartConfig
import com.esuiss.ui.components.ChartConfigItem
import com.esuiss.ui.components.ChartContainer
import com.esuiss.ui.components.ChartTooltipContent
import com.esuiss.ui.components.PieChart

private class PieDonutDeviceUsers(val device: String, val users: Double)

private val chartData = listOf(
    PieDonutDeviceUsers("phone", 275.0),
    PieDonutDeviceUsers("laptop", 200.0),
    PieDonutDeviceUsers("tablet", 187.0),
    PieDonutDeviceUsers("watch", 173.0),
    PieDonutDeviceUsers("other", 90.0),
)

private val chartConfig = ChartConfig(
    "users" to ChartConfigItem("Users"),
    "phone" to ChartConfigItem("Phone") { chart1 },
    "laptop" to ChartConfigItem("Laptop") { chart2 },
    "tablet" to ChartConfigItem("Tablet") { chart3 },
    "watch" to ChartConfigItem("Watch") { chart4 },
    "other" to ChartConfigItem("Other") { chart5 },
)

@Composable
fun PieChartDonut(modifier: Modifier = Modifier) {
    Card(modifier, variant = CardVariant.Filled, size = CardSize.Sm) {
        CardHeader("Donut", description = "A hole in the middle")
        CardContent {
            ChartContainer(
                chartConfig,
                Modifier
                    .fillMaxWidth()
                    .height(208.dp),
            ) {
                PieChart(accessibilityLabel = "Donut") {
                    ChartTooltip { ChartTooltipContent(hideLabel = true) }
                    Pie(
                        chartData,
                        value = { it.users },
                        nameKey = { it.device },
                        innerRadius = 0.58f,
                        outerRadius = 0.85f,
                        strokeWidth = 0.dp,
                        paddingAngle = 1f,
                    )
                }
            }
        }
    }
}
```

**React Native, Jetpack Compose**

A `PieChart` whose `Pie` uses `innerRadius` to leave the middle empty and `paddingAngle` to space the slices. `chartData` holds one record per device with a `users` count. Pressing a slice shows a tooltip.

**React Native**

Replace `chartData` with your records and keep `dataKey` and `nameKey` in step with your field names. Add one entry per slice to `chartConfig` with its label and color; the component takes no props.

**React Native, SwiftUI, Jetpack Compose**

### Installation

**Command**

**React Native**

```bash title="Terminal"
npx shadcn@latest add @esuiss/pie-chart-donut
```

See [Installation](https://suiss.app/ui/docs/installation) for the `components.json` setup. Or use the [suiss/ui CLI](https://suiss.app/ui/docs/cli):

```bash title="Terminal"
npx @esuiss/ui@latest add charts pie-chart-donut
```

**SwiftUI**

```bash title="Terminal"
npx shadcn@latest add @esuiss/pie-chart-donut
```

See [Installation](https://suiss.app/ui/docs/installation) for the `components.json` setup. Or use the [suiss/ui CLI](https://suiss.app/ui/docs/cli):

```bash title="Terminal"
npx @esuiss/ui@latest add charts pie-chart-donut --platform swift
```

**Jetpack Compose**

```bash title="Terminal"
npx shadcn@latest add @esuiss/pie-chart-donut
```

See [Installation](https://suiss.app/ui/docs/installation) for the `components.json` setup. Or use the [suiss/ui CLI](https://suiss.app/ui/docs/cli):

```bash title="Terminal"
npx @esuiss/ui@latest add charts pie-chart-donut --platform kotlin
```

**React Native**

The CLI also adds what it builds on: [Card](https://suiss.app/ui/docs/components/card), [Chart](https://suiss.app/ui/docs/components/chart).

**React Native, SwiftUI, Jetpack Compose**

**Manual**

**React Native**

**Uniwind**

1. Add the pieces it builds on: [Card](https://suiss.app/ui/docs/components/card), [Chart](https://suiss.app/ui/docs/components/chart).

2. Copy and paste the following code into `components/charts/pie-chart-donut.tsx`:

- `uniwind/components/charts/pie-chart-donut.tsx`: shown above

3. Update the import paths to match your project setup.

**NativeWind**

1. Add the pieces it builds on: [Card](https://suiss.app/ui/docs/components/card), [Chart](https://suiss.app/ui/docs/components/chart).

2. Copy and paste the following code into `components/charts/pie-chart-donut.tsx`:

```tsx title="nativewind/components/charts/pie-chart-donut.tsx"
import {
  Card,
  CardContent,
  CardDescription,
  CardHeader,
  CardTitle,
} from "@/components/ui/card"
import {
  type ChartConfig,
  ChartContainer,
  ChartTooltip,
  ChartTooltipContent,
  Pie,
  PieChart,
} from "@/components/ui/chart"

const chartData = [
  { device: "phone", users: 275 },
  { device: "laptop", users: 200 },
  { device: "tablet", users: 187 },
  { device: "watch", users: 173 },
  { device: "other", users: 90 },
]

const chartConfig = {
  users: { label: "Users" },
  phone: { label: "Phone", color: "chart-1" },
  laptop: { label: "Laptop", color: "chart-2" },
  tablet: { label: "Tablet", color: "chart-3" },
  watch: { label: "Watch", color: "chart-4" },
  other: { label: "Other", color: "chart-5" },
} satisfies ChartConfig

export function PieChartDonut() {
  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>Donut</CardTitle>
        <CardDescription>A hole in the middle</CardDescription>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          accessibilityLabel="Donut"
          className="h-52 w-full"
        >
          <PieChart>
            <ChartTooltip
              cursor={false}
              content={<ChartTooltipContent hideLabel nameKey="device" />}
            />
            <Pie
              data={chartData}
              dataKey="users"
              nameKey="device"
              innerRadius="58%"
              outerRadius="85%"
              strokeWidth={0}
              paddingAngle={1}
            />
          </PieChart>
        </ChartContainer>
      </CardContent>
    </Card>
  )
}
```

3. Update the import paths to match your project setup.

**StyleSheet**

1. Add the pieces it builds on: [Card](https://suiss.app/ui/docs/components/card), [Chart](https://suiss.app/ui/docs/components/chart).

2. Copy and paste the following code into `components/charts/pie-chart-donut.tsx`:

```tsx title="stylesheet/components/charts/pie-chart-donut.tsx"
import {
  Card,
  CardContent,
  CardDescription,
  CardHeader,
  CardTitle,
} from "@/components/ui/card"
import {
  type ChartConfig,
  ChartContainer,
  ChartTooltip,
  ChartTooltipContent,
  Pie,
  PieChart,
} from "@/components/ui/chart"

const chartData = [
  { device: "phone", users: 275 },
  { device: "laptop", users: 200 },
  { device: "tablet", users: 187 },
  { device: "watch", users: 173 },
  { device: "other", users: 90 },
]

const chartConfig = {
  users: { label: "Users" },
  phone: { label: "Phone", color: "chart-1" },
  laptop: { label: "Laptop", color: "chart-2" },
  tablet: { label: "Tablet", color: "chart-3" },
  watch: { label: "Watch", color: "chart-4" },
  other: { label: "Other", color: "chart-5" },
} satisfies ChartConfig

export function PieChartDonut() {
  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>Donut</CardTitle>
        <CardDescription>A hole in the middle</CardDescription>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          accessibilityLabel="Donut"
          style={{ height: 208 }}
        >
          <PieChart>
            <ChartTooltip
              cursor={false}
              content={<ChartTooltipContent hideLabel nameKey="device" />}
            />
            <Pie
              data={chartData}
              dataKey="users"
              nameKey="device"
              innerRadius="58%"
              outerRadius="85%"
              strokeWidth={0}
              paddingAngle={1}
            />
          </PieChart>
        </ChartContainer>
      </CardContent>
    </Card>
  )
}
```

3. Update the import paths to match your project setup.

**SwiftUI**

1. Target iOS 17 or later.

2. Copy the theme files every view uses:

- `swift/Theme/Theme.swift`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/swiftui/Sources/EsuissUI/Theme/Theme.swift)

- `swift/Theme/Tokens.swift`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/swiftui/Sources/EsuissUI/Theme/Tokens.swift)

3. Copy the source and every file it uses:

- `swift/Charts/PieChartDonut.swift`: shown above

- `swift/Components/Card.swift`: see [Card](https://suiss.app/ui/docs/components/card.md)

- `swift/Components/Chart.swift`: see [Chart](https://suiss.app/ui/docs/components/chart.md)

- `swift/Components/Haptics.swift`: see [Haptics](https://suiss.app/ui/docs/components/haptics.md)

- `swift/Components/Item.swift`: see [Item](https://suiss.app/ui/docs/components/item.md)

- `swift/Components/Separator.swift`: see [Separator](https://suiss.app/ui/docs/components/separator.md)

4. Add the files to your app target.

**Jetpack Compose**

1. Apply the Compose compiler plugin, enable Compose, set `compileSdk` to 37 or higher and `minSdk` to 24 or higher, and add the dependencies:

```kotlin title="build.gradle.kts"
plugins {
    id("org.jetbrains.kotlin.plugin.compose")
}

android {
    compileSdk = 37
    defaultConfig { minSdk = 24 }
    buildFeatures { compose = true }
}

dependencies {
    implementation(platform("androidx.compose:compose-bom:2026.09.00"))
    implementation("androidx.compose.foundation:foundation")
    implementation("androidx.compose.ui:ui")
}
```

2. Copy the theme files every view uses:

- `kotlin/theme/Theme.kt`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/kotlin/ui/src/main/kotlin/com/esuiss/ui/theme/Theme.kt)

- `kotlin/theme/Tokens.kt`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/kotlin/ui/src/main/kotlin/com/esuiss/ui/theme/Tokens.kt)

3. Copy the source and every file it uses:

- `kotlin/charts/PieChartDonut.kt`: shown above

- `kotlin/components/Card.kt`: see [Card](https://suiss.app/ui/docs/components/card.md)

- `kotlin/components/Chart.kt`: see [Chart](https://suiss.app/ui/docs/components/chart.md)

- `kotlin/components/Content.kt`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/kotlin/ui/src/main/kotlin/com/esuiss/ui/components/Content.kt)

- `kotlin/components/FormSupport.kt`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/kotlin/ui/src/main/kotlin/com/esuiss/ui/components/FormSupport.kt)

- `kotlin/components/Haptics.kt`: see [Haptics](https://suiss.app/ui/docs/components/haptics.md)

- `kotlin/components/Icon.kt`: see [Icon](https://suiss.app/ui/docs/components/icon.md)

4. Update the `com.esuiss.ui` package names to match your project.

**React Native, SwiftUI, Jetpack Compose**

### Usage

**React Native**

```tsx
import { PieChartDonut } from "@/components/charts/pie-chart-donut"
```

```tsx
<PieChartDonut />
```

**SwiftUI**

```swift
import SwiftUI

struct PieDonutExample: View {
  var body: some View {
    PieChartDonut()
  }
}
```

**Jetpack Compose**

```kotlin
import androidx.compose.runtime.Composable
import com.esuiss.ui.charts.PieChartDonut

@Composable
fun PieDonutExample() {
    PieChartDonut()
}
```



## Pie Chart Half

A semicircular gauge-style pie showing battery share by device, with a caption under the arc.

Source: https://suiss.app/ui/docs/charts/pie-chart#half

**React**

**Example**

```tsx title="components/charts/pie-chart-half.tsx"
"use client"

import { Pie, PieChart } from "recharts"

import {
  Card,
  CardContent,
  CardDescription,
  CardHeader,
  CardTitle,
} from "@/components/ui/card"
import {
  type ChartConfig,
  ChartContainer,
  ChartTooltip,
  ChartTooltipContent,
} from "@/components/ui/chart"

const chartData = [
  { device: "phone", share: 40, fill: "var(--color-phone)" },
  { device: "laptop", share: 25, fill: "var(--color-laptop)" },
  { device: "tablet", share: 20, fill: "var(--color-tablet)" },
  { device: "watch", share: 15, fill: "var(--color-watch)" },
]

const chartConfig = {
  share: { label: "Share" },
  phone: { label: "Phone", color: "var(--chart-1)" },
  laptop: { label: "Laptop", color: "var(--chart-2)" },
  tablet: { label: "Tablet", color: "var(--chart-3)" },
  watch: { label: "Watch", color: "var(--chart-4)" },
} satisfies ChartConfig

export function PieChartHalf() {
  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>Half circle</CardTitle>
        <CardDescription>Battery use by device · last 24 hours</CardDescription>
      </CardHeader>
      <CardContent>
        <div className="relative">
          <ChartContainer
            config={chartConfig}
            className="aspect-auto h-44 w-full"
          >
            <PieChart accessibilityLayer>
              <ChartTooltip
                cursor={false}
                content={
                  <ChartTooltipContent
                    hideLabel
                    nameKey="device"
                    formatter={(value, name) => (
                      <span>
                        {chartConfig[name as keyof typeof chartConfig].label} ·{" "}
                        <span className="font-semibold tabular-nums">
                          {value}%
                        </span>
                      </span>
                    )}
                  />
                }
              />
              <Pie
                data={chartData}
                dataKey="share"
                nameKey="device"
                cy="88%"
                startAngle={180}
                endAngle={0}
                innerRadius="105%"
                outerRadius="150%"
                paddingAngle={1.5}
                cornerRadius={4}
                stroke="none"
              />
            </PieChart>
          </ChartContainer>
          <div className="pointer-events-none absolute inset-x-0 bottom-[12%] flex flex-col items-center text-center">
            <span className="text-2xl font-semibold tracking-tight tabular-nums">
              100%
            </span>
            <span className="text-xs text-muted-foreground">last 24 hours</span>
          </div>
        </div>
      </CardContent>
    </Card>
  )
}
```

A semicircular donut that reads like a gauge, with a figure and caption tucked under the arc. Use it in compact cards where a full circle takes too much height.

Replace `chartData` with your categories and their shares, and add each key to `chartConfig`. The tooltip appends a percent sign, so change its formatter if your values aren't percentages. The figure and caption under the arc are static text. The arc's size depends on the container height, so check the fit if you change it.

### Installation

**Command**

```bash title="Terminal"
npx shadcn@latest add @esuiss/pie-chart-half
```

Works in any project with a `components.json`. See [Installation](https://suiss.app/ui/docs/installation#add-components) for the one-line registry setup. Or use the [suiss/ui CLI](https://suiss.app/ui/docs/cli):

```bash title="Terminal"
npx @esuiss/ui@latest add charts pie-chart-half
```

**Manual**

1. Install the following dependencies:

```bash title="Terminal"
npm install recharts
```

2. Add the pieces it builds on: [Card](https://suiss.app/ui/docs/components/card), [Chart](https://suiss.app/ui/docs/components/chart).

3. Copy and paste the following code into your project.

```tsx title="components/charts/pie-chart-half.tsx"
"use client"

import { Pie, PieChart } from "recharts"

import {
  Card,
  CardContent,
  CardDescription,
  CardHeader,
  CardTitle,
} from "@/components/ui/card"
import {
  type ChartConfig,
  ChartContainer,
  ChartTooltip,
  ChartTooltipContent,
} from "@/components/ui/chart"

const chartData = [
  { device: "phone", share: 40, fill: "var(--color-phone)" },
  { device: "laptop", share: 25, fill: "var(--color-laptop)" },
  { device: "tablet", share: 20, fill: "var(--color-tablet)" },
  { device: "watch", share: 15, fill: "var(--color-watch)" },
]

const chartConfig = {
  share: { label: "Share" },
  phone: { label: "Phone", color: "var(--chart-1)" },
  laptop: { label: "Laptop", color: "var(--chart-2)" },
  tablet: { label: "Tablet", color: "var(--chart-3)" },
  watch: { label: "Watch", color: "var(--chart-4)" },
} satisfies ChartConfig

export function PieChartHalf() {
  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>Half circle</CardTitle>
        <CardDescription>Battery use by device · last 24 hours</CardDescription>
      </CardHeader>
      <CardContent>
        <div className="relative">
          <ChartContainer
            config={chartConfig}
            className="aspect-auto h-44 w-full"
          >
            <PieChart accessibilityLayer>
              <ChartTooltip
                cursor={false}
                content={
                  <ChartTooltipContent
                    hideLabel
                    nameKey="device"
                    formatter={(value, name) => (
                      <span>
                        {chartConfig[name as keyof typeof chartConfig].label} ·{" "}
                        <span className="font-semibold tabular-nums">
                          {value}%
                        </span>
                      </span>
                    )}
                  />
                }
              />
              <Pie
                data={chartData}
                dataKey="share"
                nameKey="device"
                cy="88%"
                startAngle={180}
                endAngle={0}
                innerRadius="105%"
                outerRadius="150%"
                paddingAngle={1.5}
                cornerRadius={4}
                stroke="none"
              />
            </PieChart>
          </ChartContainer>
          <div className="pointer-events-none absolute inset-x-0 bottom-[12%] flex flex-col items-center text-center">
            <span className="text-2xl font-semibold tracking-tight tabular-nums">
              100%
            </span>
            <span className="text-xs text-muted-foreground">last 24 hours</span>
          </div>
        </div>
      </CardContent>
    </Card>
  )
}
```

4. Update the import paths to match your project setup.

### Usage

```tsx
import { PieChartHalf } from "@/components/charts/pie-chart-half"
```

```tsx
<PieChartHalf />
```

**React Native, SwiftUI, Jetpack Compose**

```tsx title="uniwind/components/charts/pie-chart-half.tsx"
import { View } from "react-native"
import {
  Card,
  CardContent,
  CardDescription,
  CardHeader,
  CardTitle,
} from "@/components/ui/card"
import {
  type ChartConfig,
  ChartContainer,
  ChartTooltip,
  ChartTooltipContent,
  Pie,
  PieChart,
} from "@/components/ui/chart"
import { Text } from "@/components/ui/text"

const chartData = [
  { device: "phone", share: 40 },
  { device: "laptop", share: 25 },
  { device: "tablet", share: 20 },
  { device: "watch", share: 15 },
]

const chartConfig = {
  share: { label: "Share" },
  phone: { label: "Phone", color: "chart-1" },
  laptop: { label: "Laptop", color: "chart-2" },
  tablet: { label: "Tablet", color: "chart-3" },
  watch: { label: "Watch", color: "chart-4" },
} satisfies ChartConfig

export function PieChartHalf() {
  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>Half circle</CardTitle>
        <CardDescription>Battery use by device · last 24 hours</CardDescription>
      </CardHeader>
      <CardContent>
        <View>
          <View
            pointerEvents="none"
            className="absolute inset-x-0 bottom-[12%] items-center"
          >
            <Text className="text-2xl font-semibold tracking-tight tabular-nums">
              100%
            </Text>
            <Text className="text-xs text-muted-foreground">last 24 hours</Text>
          </View>
          <ChartContainer
            config={chartConfig}
            accessibilityLabel="Half circle"
            className="h-44 w-full"
          >
            <PieChart>
              <ChartTooltip
                cursor={false}
                content={
                  <ChartTooltipContent
                    hideLabel
                    nameKey="device"
                    formatter={(value, name) => (
                      <Text>
                        {`${chartConfig[name as keyof typeof chartConfig].label} · `}
                        <Text className="font-semibold tabular-nums">
                          {`${String(value)}%`}
                        </Text>
                      </Text>
                    )}
                  />
                }
              />
              <Pie
                data={chartData}
                dataKey="share"
                nameKey="device"
                cy="88%"
                startAngle={180}
                endAngle={0}
                innerRadius="105%"
                outerRadius="150%"
                paddingAngle={1.5}
                cornerRadius={4}
                stroke="none"
              />
            </PieChart>
          </ChartContainer>
        </View>
      </CardContent>
    </Card>
  )
}
```

```swift title="swift/Charts/PieChartHalf.swift"
import Charts
import SwiftUI

private let chartData: [(device: String, share: Double)] = [
  ("phone", 40), ("laptop", 25), ("tablet", 20), ("watch", 15),
]

private let chartConfig: ChartConfig = [
  "share": .init("Share"),
  "phone": .init("Phone", color: EsuissColor.chart1),
  "laptop": .init("Laptop", color: EsuissColor.chart2),
  "tablet": .init("Tablet", color: EsuissColor.chart3),
  "watch": .init("Watch", color: EsuissColor.chart4),
]

private let total = chartData.reduce(0) { $0 + $1.share }

public struct PieChartHalf: View {
  @State private var selection: Int?

  public init() {}

  public var body: some View {
    let outer: CGFloat = 124.5
    Card(.filled, size: .sm) {
      CardHeader("Half circle", description: "Battery use by device · last 24 hours")
      CardContent {
        ChartContainer(config: chartConfig) {
          ChartAnimator { progress in
            Chart {
              ForEach(chartData, id: \.device) { item in
                SectorMark(angle: .value("Share", item.share * progress), innerRadius: .ratio(0.7), angularInset: 1)
                  .cornerRadius(4)
                  .foregroundStyle(chartConfig.color(item.device))
              }
              ChartSectorRest(total: total, progress: progress)
              SectorMark(angle: .value("Share", total))
                .foregroundStyle(.clear)
            }
            .contentShape(Rectangle().size(width: outer + 26, height: outer * 2).offset(x: outer - 26))
            .chartTooltip(
              angle: chartData.map(\.share),
              labels: chartData.map { chartConfig.label($0.device) },
              startAngle: .degrees(-90),
              endAngle: .degrees(90),
              innerRadius: 0.7,
              selection: $selection,
              accessibilityLabel: "Half circle",
              items: { [ChartTooltipItem(chartData[$0].device, value: chartData[$0].share)] }
            ) { payload in
              ChartTooltipContent(payload, hideLabel: true) { item in
                HStack(spacing: 0) {
                  Text("\(Text(LocalizedStringKey(chartConfig.label(item.key)))) · ")
                  Text(verbatim: "\(item.value.formatted(.number))%")
                    .fontWeight(.semibold)
                    .monospacedDigit()
                }
              }
            }
            .frame(width: outer * 2, height: outer * 2)
            .padding(.top, 26.5)
            .frame(maxWidth: .infinity)
            .frame(height: 176, alignment: .top)
            .overlay(alignment: .bottom) {
              VStack(spacing: 0) {
                Text(verbatim: "100%")
                  .textStyle(.xl2, weight: .semibold)
                  .monospacedDigit()
                Text("last 24 hours")
                  .textStyle(.xs)
                  .foregroundStyle(EsuissColor.mutedForeground)
              }
              .padding(.bottom, 21)
              .allowsHitTesting(false)
              .accessibilityHidden(true)
            }
          }
        }
        .frame(height: 176)
      }
    }
  }
}
```

```kt title="kotlin/charts/PieChartHalf.kt"
package com.esuiss.ui.charts

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.text.BasicText
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.semantics.clearAndSetSemantics
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import com.esuiss.ui.components.Card
import com.esuiss.ui.components.CardContent
import com.esuiss.ui.components.CardHeader
import com.esuiss.ui.components.CardSize
import com.esuiss.ui.components.CardVariant
import com.esuiss.ui.components.ChartConfig
import com.esuiss.ui.components.ChartConfigItem
import com.esuiss.ui.components.ChartContainer
import com.esuiss.ui.components.ChartTooltipContent
import com.esuiss.ui.components.PieChart
import com.esuiss.ui.theme.EsuissTheme
import com.esuiss.ui.theme.Typography
import java.text.NumberFormat
import java.util.Locale

private class PieHalfDeviceShare(val device: String, val share: Double)

private val chartData = listOf(
    PieHalfDeviceShare("phone", 40.0),
    PieHalfDeviceShare("laptop", 25.0),
    PieHalfDeviceShare("tablet", 20.0),
    PieHalfDeviceShare("watch", 15.0),
)

private val chartConfig = ChartConfig(
    "share" to ChartConfigItem("Share"),
    "phone" to ChartConfigItem("Phone") { chart1 },
    "laptop" to ChartConfigItem("Laptop") { chart2 },
    "tablet" to ChartConfigItem("Tablet") { chart3 },
    "watch" to ChartConfigItem("Watch") { chart4 },
)

@Composable
fun PieChartHalf(modifier: Modifier = Modifier) {
    val colors = EsuissTheme.colors
    val number = NumberFormat.getNumberInstance(Locale.US)
    Card(modifier, variant = CardVariant.Filled, size = CardSize.Sm) {
        CardHeader("Half circle", description = "Battery use by device · last 24 hours")
        CardContent {
            Box(
                Modifier
                    .fillMaxWidth()
                    .height(176.dp),
            ) {
                ChartContainer(chartConfig, Modifier.matchParentSize()) {
                    PieChart(accessibilityLabel = "Half circle") {
                        ChartTooltip {
                            ChartTooltipContent(
                                hideLabel = true,
                                formatter = { item ->
                                    Row {
                                        BasicText(
                                            "${chartConfig[item.key]?.label ?: item.key} · ",
                                            style = Typography.xs.copy(color = colors.foreground),
                                        )
                                        BasicText(
                                            "${number.format(item.value)}%",
                                            style = Typography.xs.copy(color = colors.foreground, fontWeight = FontWeight.SemiBold, fontFeatureSettings = "tnum"),
                                        )
                                    }
                                },
                            )
                        }
                        Pie(
                            chartData,
                            value = { it.share },
                            nameKey = { it.device },
                            cy = 0.88f,
                            startAngle = 180f,
                            endAngle = 0f,
                            innerRadius = 1.05f,
                            outerRadius = 1.5f,
                            paddingAngle = 1.5f,
                            cornerRadius = 4.dp,
                        )
                    }
                }
                Column(
                    Modifier
                        .align(Alignment.BottomCenter)
                        .padding(bottom = 21.dp)
                        .clearAndSetSemantics {},
                    horizontalAlignment = Alignment.CenterHorizontally,
                ) {
                    BasicText(
                        "100%",
                        style = Typography.xl2.copy(color = colors.foreground, fontWeight = FontWeight.SemiBold, fontFeatureSettings = "tnum"),
                    )
                    BasicText("last 24 hours", style = Typography.xs.copy(color = colors.mutedForeground))
                }
            }
        }
    }
}
```

**React Native**

A `PieChart` drawn from 180 to 0 degrees, with rounded, spaced slices. `chartData` holds a percentage `share` per device. A centered `Text` shows the 100% total, and the tooltip uses a custom `formatter` to print each share as a percentage.

Replace `chartData` with your shares and update `chartConfig` and the caption under the arc. The component takes no props.

**React Native, SwiftUI, Jetpack Compose**

### Installation

**Command**

**React Native**

```bash title="Terminal"
npx shadcn@latest add @esuiss/pie-chart-half
```

See [Installation](https://suiss.app/ui/docs/installation) for the `components.json` setup. Or use the [suiss/ui CLI](https://suiss.app/ui/docs/cli):

```bash title="Terminal"
npx @esuiss/ui@latest add charts pie-chart-half
```

**SwiftUI**

```bash title="Terminal"
npx shadcn@latest add @esuiss/pie-chart-half
```

See [Installation](https://suiss.app/ui/docs/installation) for the `components.json` setup. Or use the [suiss/ui CLI](https://suiss.app/ui/docs/cli):

```bash title="Terminal"
npx @esuiss/ui@latest add charts pie-chart-half --platform swift
```

**Jetpack Compose**

```bash title="Terminal"
npx shadcn@latest add @esuiss/pie-chart-half
```

See [Installation](https://suiss.app/ui/docs/installation) for the `components.json` setup. Or use the [suiss/ui CLI](https://suiss.app/ui/docs/cli):

```bash title="Terminal"
npx @esuiss/ui@latest add charts pie-chart-half --platform kotlin
```

**React Native**

The CLI also adds what it builds on: [Card](https://suiss.app/ui/docs/components/card), [Chart](https://suiss.app/ui/docs/components/chart), [Text](https://suiss.app/ui/docs/components/text).

**React Native, SwiftUI, Jetpack Compose**

**Manual**

**React Native**

**Uniwind**

1. Add the pieces it builds on: [Card](https://suiss.app/ui/docs/components/card), [Chart](https://suiss.app/ui/docs/components/chart), [Text](https://suiss.app/ui/docs/components/text).

2. Copy and paste the following code into `components/charts/pie-chart-half.tsx`:

- `uniwind/components/charts/pie-chart-half.tsx`: shown above

3. Update the import paths to match your project setup.

**NativeWind**

1. Add the pieces it builds on: [Card](https://suiss.app/ui/docs/components/card), [Chart](https://suiss.app/ui/docs/components/chart), [Text](https://suiss.app/ui/docs/components/text).

2. Copy and paste the following code into `components/charts/pie-chart-half.tsx`:

```tsx title="nativewind/components/charts/pie-chart-half.tsx"
import { View } from "react-native"
import {
  Card,
  CardContent,
  CardDescription,
  CardHeader,
  CardTitle,
} from "@/components/ui/card"
import {
  type ChartConfig,
  ChartContainer,
  ChartTooltip,
  ChartTooltipContent,
  Pie,
  PieChart,
} from "@/components/ui/chart"
import { Text } from "@/components/ui/text"

const chartData = [
  { device: "phone", share: 40 },
  { device: "laptop", share: 25 },
  { device: "tablet", share: 20 },
  { device: "watch", share: 15 },
]

const chartConfig = {
  share: { label: "Share" },
  phone: { label: "Phone", color: "chart-1" },
  laptop: { label: "Laptop", color: "chart-2" },
  tablet: { label: "Tablet", color: "chart-3" },
  watch: { label: "Watch", color: "chart-4" },
} satisfies ChartConfig

export function PieChartHalf() {
  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>Half circle</CardTitle>
        <CardDescription>Battery use by device · last 24 hours</CardDescription>
      </CardHeader>
      <CardContent>
        <View>
          <View
            pointerEvents="none"
            className="absolute inset-x-0 bottom-[12%] items-center"
          >
            <Text className="text-2xl font-semibold tracking-tight tabular-nums">
              100%
            </Text>
            <Text className="text-xs text-muted-foreground">last 24 hours</Text>
          </View>
          <ChartContainer
            config={chartConfig}
            accessibilityLabel="Half circle"
            className="h-44 w-full"
          >
            <PieChart>
              <ChartTooltip
                cursor={false}
                content={
                  <ChartTooltipContent
                    hideLabel
                    nameKey="device"
                    formatter={(value, name) => (
                      <Text>
                        {`${chartConfig[name as keyof typeof chartConfig].label} · `}
                        <Text className="font-semibold tabular-nums">
                          {`${String(value)}%`}
                        </Text>
                      </Text>
                    )}
                  />
                }
              />
              <Pie
                data={chartData}
                dataKey="share"
                nameKey="device"
                cy="88%"
                startAngle={180}
                endAngle={0}
                innerRadius="105%"
                outerRadius="150%"
                paddingAngle={1.5}
                cornerRadius={4}
                stroke="none"
              />
            </PieChart>
          </ChartContainer>
        </View>
      </CardContent>
    </Card>
  )
}
```

3. Update the import paths to match your project setup.

**StyleSheet**

1. Add the pieces it builds on: [Card](https://suiss.app/ui/docs/components/card), [Chart](https://suiss.app/ui/docs/components/chart), [Text](https://suiss.app/ui/docs/components/text).

2. Copy and paste the following code into `components/charts/pie-chart-half.tsx`:

```tsx title="stylesheet/components/charts/pie-chart-half.tsx"
import { StyleSheet, View } from "react-native"
import {
  Card,
  CardContent,
  CardDescription,
  CardHeader,
  CardTitle,
} from "@/components/ui/card"
import {
  type ChartConfig,
  ChartContainer,
  ChartTooltip,
  ChartTooltipContent,
  Pie,
  PieChart,
} from "@/components/ui/chart"
import { Text } from "@/components/ui/text"
import { fontSize, useTheme } from "@/components/ui/theme"

const chartData = [
  { device: "phone", share: 40 },
  { device: "laptop", share: 25 },
  { device: "tablet", share: 20 },
  { device: "watch", share: 15 },
]

const chartConfig = {
  share: { label: "Share" },
  phone: { label: "Phone", color: "chart-1" },
  laptop: { label: "Laptop", color: "chart-2" },
  tablet: { label: "Tablet", color: "chart-3" },
  watch: { label: "Watch", color: "chart-4" },
} satisfies ChartConfig

const styles = StyleSheet.create({
  overlay: {
    position: "absolute",
    left: 0,
    right: 0,
    bottom: "12%",
    alignItems: "center",
  },
  value: {
    ...fontSize["2xl"],
    fontWeight: "600",
    letterSpacing: -0.7,
    fontVariant: ["tabular-nums"],
  },
  caption: { ...fontSize.xs },
  strong: { fontWeight: "600", fontVariant: ["tabular-nums"] },
  chart: { height: 176 },
})

export function PieChartHalf() {
  const { colors } = useTheme()
  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>Half circle</CardTitle>
        <CardDescription>Battery use by device · last 24 hours</CardDescription>
      </CardHeader>
      <CardContent>
        <View>
          <View pointerEvents="none" style={styles.overlay}>
            <Text style={styles.value}>100%</Text>
            <Text style={[styles.caption, { color: colors.mutedForeground }]}>
              last 24 hours
            </Text>
          </View>
          <ChartContainer
            config={chartConfig}
            accessibilityLabel="Half circle"
            style={styles.chart}
          >
            <PieChart>
              <ChartTooltip
                cursor={false}
                content={
                  <ChartTooltipContent
                    hideLabel
                    nameKey="device"
                    formatter={(value, name) => (
                      <Text>
                        {`${chartConfig[name as keyof typeof chartConfig].label} · `}
                        <Text style={styles.strong}>{`${String(value)}%`}</Text>
                      </Text>
                    )}
                  />
                }
              />
              <Pie
                data={chartData}
                dataKey="share"
                nameKey="device"
                cy="88%"
                startAngle={180}
                endAngle={0}
                innerRadius="105%"
                outerRadius="150%"
                paddingAngle={1.5}
                cornerRadius={4}
                stroke="none"
              />
            </PieChart>
          </ChartContainer>
        </View>
      </CardContent>
    </Card>
  )
}
```

3. Update the import paths to match your project setup.

**SwiftUI**

1. Target iOS 17 or later.

2. Copy the theme files every view uses:

- `swift/Theme/Theme.swift`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/swiftui/Sources/EsuissUI/Theme/Theme.swift)

- `swift/Theme/Tokens.swift`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/swiftui/Sources/EsuissUI/Theme/Tokens.swift)

3. Copy the source and every file it uses:

- `swift/Charts/PieChartHalf.swift`: shown above

- `swift/Components/Card.swift`: see [Card](https://suiss.app/ui/docs/components/card.md)

- `swift/Components/Chart.swift`: see [Chart](https://suiss.app/ui/docs/components/chart.md)

- `swift/Components/Haptics.swift`: see [Haptics](https://suiss.app/ui/docs/components/haptics.md)

- `swift/Components/Item.swift`: see [Item](https://suiss.app/ui/docs/components/item.md)

- `swift/Components/Separator.swift`: see [Separator](https://suiss.app/ui/docs/components/separator.md)

4. Add the files to your app target.

**Jetpack Compose**

1. Apply the Compose compiler plugin, enable Compose, set `compileSdk` to 37 or higher and `minSdk` to 24 or higher, and add the dependencies:

```kotlin title="build.gradle.kts"
plugins {
    id("org.jetbrains.kotlin.plugin.compose")
}

android {
    compileSdk = 37
    defaultConfig { minSdk = 24 }
    buildFeatures { compose = true }
}

dependencies {
    implementation(platform("androidx.compose:compose-bom:2026.09.00"))
    implementation("androidx.compose.foundation:foundation")
    implementation("androidx.compose.ui:ui")
}
```

2. Copy the theme files every view uses:

- `kotlin/theme/Theme.kt`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/kotlin/ui/src/main/kotlin/com/esuiss/ui/theme/Theme.kt)

- `kotlin/theme/Tokens.kt`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/kotlin/ui/src/main/kotlin/com/esuiss/ui/theme/Tokens.kt)

3. Copy the source and every file it uses:

- `kotlin/charts/PieChartHalf.kt`: shown above

- `kotlin/components/Card.kt`: see [Card](https://suiss.app/ui/docs/components/card.md)

- `kotlin/components/Chart.kt`: see [Chart](https://suiss.app/ui/docs/components/chart.md)

- `kotlin/components/Content.kt`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/kotlin/ui/src/main/kotlin/com/esuiss/ui/components/Content.kt)

- `kotlin/components/FormSupport.kt`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/kotlin/ui/src/main/kotlin/com/esuiss/ui/components/FormSupport.kt)

- `kotlin/components/Haptics.kt`: see [Haptics](https://suiss.app/ui/docs/components/haptics.md)

- `kotlin/components/Icon.kt`: see [Icon](https://suiss.app/ui/docs/components/icon.md)

4. Update the `com.esuiss.ui` package names to match your project.

**React Native, SwiftUI, Jetpack Compose**

### Usage

**React Native**

```tsx
import { PieChartHalf } from "@/components/charts/pie-chart-half"
```

```tsx
<PieChartHalf />
```

**SwiftUI**

```swift
import SwiftUI

struct PieHalfExample: View {
  var body: some View {
    PieChartHalf()
  }
}
```

**Jetpack Compose**

```kotlin
import androidx.compose.runtime.Composable
import com.esuiss.ui.charts.PieChartHalf

@Composable
fun PieHalfExample() {
    PieChartHalf()
}
```



## Pie Chart Interactive

A storage breakdown donut with a device switch, hover-linked list and lifted slices, plus a linear usage bar.

Source: https://suiss.app/ui/docs/charts/pie-chart#interactive

**React**

**Example**

```tsx title="components/charts/pie-chart-interactive.tsx"
"use client"

import * as React from "react"
import { Pie, PieChart, Sector } from "recharts"

import { Card, CardContent, CardHeader } from "@/components/ui/card"
import { type ChartConfig, ChartContainer } from "@/components/ui/chart"
import { ToggleGroup, ToggleGroupItem } from "@/components/ui/toggle-group"

type Device = "phone" | "cloud"

type Kind =
  | "apps"
  | "photos"
  | "system"
  | "backups"
  | "drive"
  | "messages"
  | "mail"
  | "other"
  | "free"

const KINDS: Kind[] = [
  "apps",
  "photos",
  "system",
  "backups",
  "drive",
  "messages",
  "mail",
  "other",
  "free",
]

const STORAGE: Record<
  Device,
  { label: string; total: number; used: Partial<Record<Kind, number>> }
> = {
  phone: {
    label: "Phone",
    total: 256,
    used: { apps: 62.4, photos: 48.1, system: 25.8, messages: 9.8, other: 6.3 },
  },
  cloud: {
    label: "Cloud",
    total: 200,
    used: {
      photos: 96.2,
      backups: 31.4,
      drive: 18.7,
      messages: 7.9,
      mail: 2.3,
    },
  },
}

const chartConfig = {
  apps: { label: "Apps", color: "var(--color-red-500)" },
  photos: { label: "Photos", color: "var(--chart-4)" },
  system: { label: "System", color: "var(--chart-5)" },
  backups: { label: "Backups", color: "var(--color-purple-500)" },
  drive: { label: "Drive", color: "var(--chart-1)" },
  messages: { label: "Messages", color: "var(--color-green-500)" },
  mail: { label: "Mail", color: "var(--color-cyan-500)" },
  other: { label: "Other", color: "var(--color-yellow-500)" },
  free: { label: "Free", color: "var(--secondary)" },
} satisfies ChartConfig

const MORPH_DURATION = 700
const LIFT_DURATION = 260
const LIFT = 7

const sizeFormat = new Intl.NumberFormat("en-US", {
  minimumFractionDigits: 1,
  maximumFractionDigits: 1,
})

function sizes(device: Device) {
  const { total, used } = STORAGE[device]
  const taken = Object.values(used).reduce((sum, value) => sum + value, 0)
  return KINDS.map((kind) =>
    kind === "free" ? total - taken : (used[kind] ?? 0)
  )
}

function useMorph(target: number[], duration: number) {
  const [values, setValues] = React.useState(target)
  const valuesRef = React.useRef(values)

  React.useEffect(() => {
    const from = valuesRef.current
    if (target.every((value, index) => value === from[index])) return
    const reduced = window.matchMedia(
      "(prefers-reduced-motion: reduce)"
    ).matches
    const start = performance.now()
    let frame = 0
    const step = () => {
      const progress = reduced
        ? 1
        : Math.min(1, (performance.now() - start) / duration)
      const eased =
        progress < 0.5 ? 4 * progress ** 3 : 1 - (-2 * progress + 2) ** 3 / 2
      const next =
        progress < 1
          ? target.map((value, index) => {
              const origin = from[index] ?? value
              return origin + (value - origin) * eased
            })
          : target
      valuesRef.current = next
      setValues(next)
      if (progress < 1) frame = requestAnimationFrame(step)
    }
    frame = requestAnimationFrame(step)
    return () => cancelAnimationFrame(frame)
  }, [target, duration])

  return values
}

export function PieChartInteractive() {
  const [device, setDevice] = React.useState<Device>("phone")
  const [active, setActive] = React.useState<Kind | null>(null)
  const sourceRef = React.useRef<"pie" | "list" | null>(null)

  const point = (kind: Kind) => {
    sourceRef.current = "list"
    setActive(kind)
  }
  const release = () => {
    sourceRef.current = null
    setActive(null)
  }
  const target = React.useMemo(() => sizes(device), [device])
  const values = useMorph(target, MORPH_DURATION)
  const liftTarget = React.useMemo(
    () => KINDS.map((kind) => (kind === active ? 1 : 0)),
    [active]
  )
  const lift = useMorph(liftTarget, LIFT_DURATION)
  const sizeOf = (kind: Kind) => values[KINDS.indexOf(kind)] ?? 0
  const total = values.reduce((sum, value) => sum + value, 0)
  const used = total - sizeOf("free")
  const activeValue = active ? sizeOf(active) : used
  const targetOf = (kind: Kind) => target[KINDS.indexOf(kind)] ?? 0
  const targetTotal = target.reduce((sum, value) => sum + value, 0)
  const targetValue = active ? targetOf(active) : targetTotal - targetOf("free")
  const data = React.useMemo(
    () =>
      KINDS.map((kind, index) => ({
        kind,
        size: Math.max(0, values[index] ?? 0),
        fill: `var(--color-${kind})`,
      })),
    [values]
  )

  return (
    <Card variant="filled" size="sm" className="[--card-spacing:--spacing(5)]">
      <CardHeader className="flex flex-wrap items-start justify-between gap-4">
        <div className="flex min-w-48 flex-1 flex-col gap-0.5">
          <p className="text-lg font-semibold">
            {STORAGE[device].label} storage
          </p>
          <p className="text-sm text-muted-foreground tabular-nums">
            {sizeFormat.format(used)} GB of {STORAGE[device].total} GB used
          </p>
        </div>
        <ToggleGroup
          spacing={0}
          value={[device]}
          onValueChange={(value: string[]) => {
            if (!value[0]) return
            setDevice(value[0] as Device)
            setActive(null)
          }}
          aria-label="Device"
        >
          {(Object.keys(STORAGE) as Device[]).map((key) => (
            <ToggleGroupItem key={key} value={key} size="sm" className="px-5">
              {STORAGE[key].label}
            </ToggleGroupItem>
          ))}
        </ToggleGroup>
      </CardHeader>
      <CardContent className="flex flex-col gap-5">
        <div
          aria-hidden
          className="flex h-2.5 overflow-hidden rounded-full bg-secondary"
        >
          {KINDS.filter((kind) => kind !== "free").map((kind) => {
            const share = (Math.max(0, sizeOf(kind)) / total) * 100
            return (
              <span
                key={kind}
                onPointerEnter={() => point(kind)}
                onPointerLeave={release}
                data-dimmed={active && active !== kind ? "" : undefined}
                className="h-full bg-(--swatch) transition-opacity duration-200 data-dimmed:opacity-35"
                style={
                  {
                    width: `${share}%`,
                    marginInlineEnd: Math.min(2, share * 4),
                    "--swatch": chartConfig[kind].color,
                  } as React.CSSProperties
                }
              />
            )
          })}
        </div>
        <div className="flex flex-wrap items-center gap-6">
          <div className="relative mx-auto size-70 max-w-full shrink-0">
            <ChartContainer
              config={chartConfig}
              className="aspect-square size-full"
            >
              <PieChart accessibilityLayer={false}>
                <Pie
                  data={data}
                  dataKey="size"
                  nameKey="kind"
                  innerRadius="64%"
                  outerRadius="88%"
                  startAngle={90}
                  endAngle={-270}
                  stroke="var(--muted)"
                  strokeWidth={3}
                  cornerRadius={4}
                  isAnimationActive={false}
                  onMouseEnter={(_, index) => {
                    const kind = KINDS[index]
                    if (!kind) return
                    sourceRef.current = "pie"
                    setActive(kind)
                  }}
                  onMouseLeave={() => {
                    if (sourceRef.current === "pie") release()
                  }}
                  shape={(props, index) => (
                    <Sector
                      {...props}
                      outerRadius={
                        (props.outerRadius ?? 0) +
                        (typeof index === "number" ? (lift[index] ?? 0) : 0) *
                          LIFT
                      }
                    />
                  )}
                />
              </PieChart>
            </ChartContainer>
            <p className="sr-only" aria-live="polite">
              {active ? chartConfig[active].label : "Used"}:{" "}
              {sizeFormat.format(targetValue)} GB,{" "}
              {Math.round((targetValue / targetTotal) * 100)}%
            </p>
            <div
              aria-hidden
              className="pointer-events-none absolute inset-0 flex flex-col items-center justify-center text-center"
            >
              <span className="text-sm text-muted-foreground">
                {active ? chartConfig[active].label : "Used"}
              </span>
              <span className="text-3xl font-semibold tracking-tight tabular-nums">
                {sizeFormat.format(activeValue)} GB
              </span>
              <span className="text-sm text-muted-foreground tabular-nums">
                {Math.round((activeValue / total) * 100)}%
              </span>
            </div>
          </div>
          <ul className="flex min-w-0 flex-[1_1_15rem] flex-col">
            {KINDS.map((kind) => {
              const present = (target[KINDS.indexOf(kind)] ?? 0) > 0
              return (
                <li
                  key={kind}
                  data-present={present ? "" : undefined}
                  inert={!present}
                  className="grid grid-rows-[0fr] opacity-0 transition-[grid-template-rows,opacity] duration-500 ease-[cubic-bezier(0.45,0,0.2,1)] data-present:grid-rows-[1fr] data-present:opacity-100"
                >
                  <div className="min-h-0 overflow-hidden">
                    <div
                      onPointerEnter={() => point(kind)}
                      onPointerLeave={release}
                      data-active={active === kind ? "" : undefined}
                      className="flex items-center gap-2.5 rounded-lg px-2 py-2.25 transition-colors duration-150 data-active:bg-secondary"
                    >
                      <span
                        className="size-2.5 shrink-0 rounded-full bg-(--swatch) data-[kind=free]:ring-1 data-[kind=free]:ring-input data-[kind=free]:ring-inset"
                        data-kind={kind}
                        style={
                          {
                            "--swatch": chartConfig[kind].color,
                          } as React.CSSProperties
                        }
                      />
                      <span className="flex-1 text-base">
                        {chartConfig[kind].label}
                      </span>
                      <span className="text-base text-muted-foreground tabular-nums">
                        {sizeFormat.format(Math.max(0, sizeOf(kind)))} GB
                      </span>
                    </div>
                  </div>
                </li>
              )
            })}
          </ul>
        </div>
      </CardContent>
    </Card>
  )
}
```

A storage breakdown with a Phone and Cloud switch, a stacked usage bar, a donut whose hovered slice lifts out and a list linked to it. The center shows the used total or the hovered category, and the slices morph when you switch devices. Use it as a reference for a rich part-to-whole view with linked controls.

Replace `STORAGE` with your sources, each with a total and the size of every category, list the categories in `KINDS` and add a label and color for each to `chartConfig`. Free space is computed from the total, and each source adds a toggle. Hovering the slices, the bar or the list highlights a category, but list rows aren't focusable, so keyboard users only get the totals. The center readout is a live region, and the morph is skipped when reduced motion is preferred.

### Installation

**Command**

```bash title="Terminal"
npx shadcn@latest add @esuiss/pie-chart-interactive
```

Works in any project with a `components.json`. See [Installation](https://suiss.app/ui/docs/installation#add-components) for the one-line registry setup. Or use the [suiss/ui CLI](https://suiss.app/ui/docs/cli):

```bash title="Terminal"
npx @esuiss/ui@latest add charts pie-chart-interactive
```

**Manual**

1. Install the following dependencies:

```bash title="Terminal"
npm install recharts
```

2. Add the pieces it builds on: [Card](https://suiss.app/ui/docs/components/card), [Chart](https://suiss.app/ui/docs/components/chart), [Toggle Group](https://suiss.app/ui/docs/components/toggle-group).

3. Copy and paste the following code into your project.

```tsx title="components/charts/pie-chart-interactive.tsx"
"use client"

import * as React from "react"
import { Pie, PieChart, Sector } from "recharts"

import { Card, CardContent, CardHeader } from "@/components/ui/card"
import { type ChartConfig, ChartContainer } from "@/components/ui/chart"
import { ToggleGroup, ToggleGroupItem } from "@/components/ui/toggle-group"

type Device = "phone" | "cloud"

type Kind =
  | "apps"
  | "photos"
  | "system"
  | "backups"
  | "drive"
  | "messages"
  | "mail"
  | "other"
  | "free"

const KINDS: Kind[] = [
  "apps",
  "photos",
  "system",
  "backups",
  "drive",
  "messages",
  "mail",
  "other",
  "free",
]

const STORAGE: Record<
  Device,
  { label: string; total: number; used: Partial<Record<Kind, number>> }
> = {
  phone: {
    label: "Phone",
    total: 256,
    used: { apps: 62.4, photos: 48.1, system: 25.8, messages: 9.8, other: 6.3 },
  },
  cloud: {
    label: "Cloud",
    total: 200,
    used: {
      photos: 96.2,
      backups: 31.4,
      drive: 18.7,
      messages: 7.9,
      mail: 2.3,
    },
  },
}

const chartConfig = {
  apps: { label: "Apps", color: "var(--color-red-500)" },
  photos: { label: "Photos", color: "var(--chart-4)" },
  system: { label: "System", color: "var(--chart-5)" },
  backups: { label: "Backups", color: "var(--color-purple-500)" },
  drive: { label: "Drive", color: "var(--chart-1)" },
  messages: { label: "Messages", color: "var(--color-green-500)" },
  mail: { label: "Mail", color: "var(--color-cyan-500)" },
  other: { label: "Other", color: "var(--color-yellow-500)" },
  free: { label: "Free", color: "var(--secondary)" },
} satisfies ChartConfig

const MORPH_DURATION = 700
const LIFT_DURATION = 260
const LIFT = 7

const sizeFormat = new Intl.NumberFormat("en-US", {
  minimumFractionDigits: 1,
  maximumFractionDigits: 1,
})

function sizes(device: Device) {
  const { total, used } = STORAGE[device]
  const taken = Object.values(used).reduce((sum, value) => sum + value, 0)
  return KINDS.map((kind) =>
    kind === "free" ? total - taken : (used[kind] ?? 0)
  )
}

function useMorph(target: number[], duration: number) {
  const [values, setValues] = React.useState(target)
  const valuesRef = React.useRef(values)

  React.useEffect(() => {
    const from = valuesRef.current
    if (target.every((value, index) => value === from[index])) return
    const reduced = window.matchMedia(
      "(prefers-reduced-motion: reduce)"
    ).matches
    const start = performance.now()
    let frame = 0
    const step = () => {
      const progress = reduced
        ? 1
        : Math.min(1, (performance.now() - start) / duration)
      const eased =
        progress < 0.5 ? 4 * progress ** 3 : 1 - (-2 * progress + 2) ** 3 / 2
      const next =
        progress < 1
          ? target.map((value, index) => {
              const origin = from[index] ?? value
              return origin + (value - origin) * eased
            })
          : target
      valuesRef.current = next
      setValues(next)
      if (progress < 1) frame = requestAnimationFrame(step)
    }
    frame = requestAnimationFrame(step)
    return () => cancelAnimationFrame(frame)
  }, [target, duration])

  return values
}

export function PieChartInteractive() {
  const [device, setDevice] = React.useState<Device>("phone")
  const [active, setActive] = React.useState<Kind | null>(null)
  const sourceRef = React.useRef<"pie" | "list" | null>(null)

  const point = (kind: Kind) => {
    sourceRef.current = "list"
    setActive(kind)
  }
  const release = () => {
    sourceRef.current = null
    setActive(null)
  }
  const target = React.useMemo(() => sizes(device), [device])
  const values = useMorph(target, MORPH_DURATION)
  const liftTarget = React.useMemo(
    () => KINDS.map((kind) => (kind === active ? 1 : 0)),
    [active]
  )
  const lift = useMorph(liftTarget, LIFT_DURATION)
  const sizeOf = (kind: Kind) => values[KINDS.indexOf(kind)] ?? 0
  const total = values.reduce((sum, value) => sum + value, 0)
  const used = total - sizeOf("free")
  const activeValue = active ? sizeOf(active) : used
  const targetOf = (kind: Kind) => target[KINDS.indexOf(kind)] ?? 0
  const targetTotal = target.reduce((sum, value) => sum + value, 0)
  const targetValue = active ? targetOf(active) : targetTotal - targetOf("free")
  const data = React.useMemo(
    () =>
      KINDS.map((kind, index) => ({
        kind,
        size: Math.max(0, values[index] ?? 0),
        fill: `var(--color-${kind})`,
      })),
    [values]
  )

  return (
    <Card variant="filled" size="sm" className="[--card-spacing:--spacing(5)]">
      <CardHeader className="flex flex-wrap items-start justify-between gap-4">
        <div className="flex min-w-48 flex-1 flex-col gap-0.5">
          <p className="text-lg font-semibold">
            {STORAGE[device].label} storage
          </p>
          <p className="text-sm text-muted-foreground tabular-nums">
            {sizeFormat.format(used)} GB of {STORAGE[device].total} GB used
          </p>
        </div>
        <ToggleGroup
          spacing={0}
          value={[device]}
          onValueChange={(value: string[]) => {
            if (!value[0]) return
            setDevice(value[0] as Device)
            setActive(null)
          }}
          aria-label="Device"
        >
          {(Object.keys(STORAGE) as Device[]).map((key) => (
            <ToggleGroupItem key={key} value={key} size="sm" className="px-5">
              {STORAGE[key].label}
            </ToggleGroupItem>
          ))}
        </ToggleGroup>
      </CardHeader>
      <CardContent className="flex flex-col gap-5">
        <div
          aria-hidden
          className="flex h-2.5 overflow-hidden rounded-full bg-secondary"
        >
          {KINDS.filter((kind) => kind !== "free").map((kind) => {
            const share = (Math.max(0, sizeOf(kind)) / total) * 100
            return (
              <span
                key={kind}
                onPointerEnter={() => point(kind)}
                onPointerLeave={release}
                data-dimmed={active && active !== kind ? "" : undefined}
                className="h-full bg-(--swatch) transition-opacity duration-200 data-dimmed:opacity-35"
                style={
                  {
                    width: `${share}%`,
                    marginInlineEnd: Math.min(2, share * 4),
                    "--swatch": chartConfig[kind].color,
                  } as React.CSSProperties
                }
              />
            )
          })}
        </div>
        <div className="flex flex-wrap items-center gap-6">
          <div className="relative mx-auto size-70 max-w-full shrink-0">
            <ChartContainer
              config={chartConfig}
              className="aspect-square size-full"
            >
              <PieChart accessibilityLayer={false}>
                <Pie
                  data={data}
                  dataKey="size"
                  nameKey="kind"
                  innerRadius="64%"
                  outerRadius="88%"
                  startAngle={90}
                  endAngle={-270}
                  stroke="var(--muted)"
                  strokeWidth={3}
                  cornerRadius={4}
                  isAnimationActive={false}
                  onMouseEnter={(_, index) => {
                    const kind = KINDS[index]
                    if (!kind) return
                    sourceRef.current = "pie"
                    setActive(kind)
                  }}
                  onMouseLeave={() => {
                    if (sourceRef.current === "pie") release()
                  }}
                  shape={(props, index) => (
                    <Sector
                      {...props}
                      outerRadius={
                        (props.outerRadius ?? 0) +
                        (typeof index === "number" ? (lift[index] ?? 0) : 0) *
                          LIFT
                      }
                    />
                  )}
                />
              </PieChart>
            </ChartContainer>
            <p className="sr-only" aria-live="polite">
              {active ? chartConfig[active].label : "Used"}:{" "}
              {sizeFormat.format(targetValue)} GB,{" "}
              {Math.round((targetValue / targetTotal) * 100)}%
            </p>
            <div
              aria-hidden
              className="pointer-events-none absolute inset-0 flex flex-col items-center justify-center text-center"
            >
              <span className="text-sm text-muted-foreground">
                {active ? chartConfig[active].label : "Used"}
              </span>
              <span className="text-3xl font-semibold tracking-tight tabular-nums">
                {sizeFormat.format(activeValue)} GB
              </span>
              <span className="text-sm text-muted-foreground tabular-nums">
                {Math.round((activeValue / total) * 100)}%
              </span>
            </div>
          </div>
          <ul className="flex min-w-0 flex-[1_1_15rem] flex-col">
            {KINDS.map((kind) => {
              const present = (target[KINDS.indexOf(kind)] ?? 0) > 0
              return (
                <li
                  key={kind}
                  data-present={present ? "" : undefined}
                  inert={!present}
                  className="grid grid-rows-[0fr] opacity-0 transition-[grid-template-rows,opacity] duration-500 ease-[cubic-bezier(0.45,0,0.2,1)] data-present:grid-rows-[1fr] data-present:opacity-100"
                >
                  <div className="min-h-0 overflow-hidden">
                    <div
                      onPointerEnter={() => point(kind)}
                      onPointerLeave={release}
                      data-active={active === kind ? "" : undefined}
                      className="flex items-center gap-2.5 rounded-lg px-2 py-2.25 transition-colors duration-150 data-active:bg-secondary"
                    >
                      <span
                        className="size-2.5 shrink-0 rounded-full bg-(--swatch) data-[kind=free]:ring-1 data-[kind=free]:ring-input data-[kind=free]:ring-inset"
                        data-kind={kind}
                        style={
                          {
                            "--swatch": chartConfig[kind].color,
                          } as React.CSSProperties
                        }
                      />
                      <span className="flex-1 text-base">
                        {chartConfig[kind].label}
                      </span>
                      <span className="text-base text-muted-foreground tabular-nums">
                        {sizeFormat.format(Math.max(0, sizeOf(kind)))} GB
                      </span>
                    </div>
                  </div>
                </li>
              )
            })}
          </ul>
        </div>
      </CardContent>
    </Card>
  )
}
```

4. Update the import paths to match your project setup.

### Usage

```tsx
import { PieChartInteractive } from "@/components/charts/pie-chart-interactive"
```

```tsx
<PieChartInteractive />
```

**React Native, SwiftUI, Jetpack Compose**

```tsx title="uniwind/components/charts/pie-chart-interactive.tsx"
import { cn } from "cn"
import * as React from "react"
import { Pressable, View } from "react-native"
import { Card, CardContent, CardHeader } from "@/components/ui/card"
import {
  type ChartConfig,
  ChartContainer,
  Pie,
  PieChart,
} from "@/components/ui/chart"
import { Text } from "@/components/ui/text"
import { ToggleGroup, ToggleGroupItem } from "@/components/ui/toggle-group"

type Device = "phone" | "cloud"

type Kind =
  | "apps"
  | "photos"
  | "system"
  | "backups"
  | "drive"
  | "messages"
  | "mail"
  | "other"
  | "free"

const KINDS: Kind[] = [
  "apps",
  "photos",
  "system",
  "backups",
  "drive",
  "messages",
  "mail",
  "other",
  "free",
]

const STORAGE: Record<
  Device,
  { label: string; total: number; used: Partial<Record<Kind, number>> }
> = {
  phone: {
    label: "Phone",
    total: 256,
    used: { apps: 62.4, photos: 48.1, system: 25.8, messages: 9.8, other: 6.3 },
  },
  cloud: {
    label: "Cloud",
    total: 200,
    used: {
      photos: 96.2,
      backups: 31.4,
      drive: 18.7,
      messages: 7.9,
      mail: 2.3,
    },
  },
}

const chartConfig = {
  apps: { label: "Apps", color: "red-500" },
  photos: { label: "Photos", color: "chart-4" },
  system: { label: "System", color: "chart-5" },
  backups: { label: "Backups", color: "purple-500" },
  drive: { label: "Drive", color: "chart-1" },
  messages: { label: "Messages", color: "green-500" },
  mail: { label: "Mail", color: "cyan-500" },
  other: { label: "Other", color: "yellow-500" },
  free: { label: "Free", color: "secondary" },
} satisfies ChartConfig

const SWATCH: Record<Kind, string> = {
  apps: "bg-red-500",
  photos: "bg-orange-500",
  system: "bg-zinc-500",
  backups: "bg-purple-500",
  drive: "bg-blue-500",
  messages: "bg-green-500",
  mail: "bg-cyan-500",
  other: "bg-yellow-500",
  free: "bg-secondary border border-input",
}

const LIFT = 7

function formatSize(value: number) {
  try {
    return new Intl.NumberFormat("en-US", {
      minimumFractionDigits: 1,
      maximumFractionDigits: 1,
    }).format(value)
  } catch {
    return value.toFixed(1)
  }
}

function sizes(device: Device) {
  const { total, used } = STORAGE[device]
  const taken = Object.values(used).reduce((sum, value) => sum + value, 0)
  return KINDS.map((kind) =>
    kind === "free" ? total - taken : (used[kind] ?? 0)
  )
}

export function PieChartInteractive() {
  const [device, setDevice] = React.useState<Device>("phone")
  const [active, setActive] = React.useState<Kind | null>(null)
  const values = React.useMemo(() => sizes(device), [device])
  const sizeOf = (kind: Kind) => values[KINDS.indexOf(kind)] ?? 0
  const total = values.reduce((sum, value) => sum + value, 0)
  const used = total - sizeOf("free")
  const activeValue = active ? sizeOf(active) : used
  const data = KINDS.map((kind, index) => ({
    kind,
    size: Math.max(0, values[index] ?? 0),
  }))

  return (
    <Card variant="filled" size="sm">
      <CardHeader className="flex-row flex-wrap items-start justify-between gap-4">
        <View className="min-w-48 grow gap-0.5">
          <Text className="text-lg font-semibold">
            {`${STORAGE[device].label} storage`}
          </Text>
          <Text className="text-sm text-muted-foreground tabular-nums">
            {`${formatSize(used)} GB of ${STORAGE[device].total} GB used`}
          </Text>
        </View>
        <ToggleGroup
          spacing={0}
          value={[device]}
          onValueChange={(value) => {
            if (!value[0]) return
            setDevice(value[0] as Device)
            setActive(null)
          }}
          accessibilityLabel="Device"
        >
          {(Object.keys(STORAGE) as Device[]).map((key) => (
            <ToggleGroupItem key={key} value={key} size="sm" className="px-5">
              <Text>{STORAGE[key].label}</Text>
            </ToggleGroupItem>
          ))}
        </ToggleGroup>
      </CardHeader>
      <CardContent className="gap-5">
        <View
          accessibilityElementsHidden
          importantForAccessibility="no-hide-descendants"
          className="h-2.5 flex-row overflow-hidden rounded-full bg-secondary"
        >
          {KINDS.filter((kind) => kind !== "free").map((kind) => {
            const share = (Math.max(0, sizeOf(kind)) / total) * 100
            return (
              <View
                key={kind}
                style={{
                  width: `${share}%`,
                  marginEnd: Math.min(2, share * 4),
                }}
                className={cn(
                  "h-full",
                  SWATCH[kind],
                  active && active !== kind && "opacity-35"
                )}
              />
            )
          })}
        </View>
        <View className="flex-row flex-wrap items-center justify-center gap-6">
          <View className="size-70 max-w-full">
            <View
              pointerEvents="none"
              accessibilityLiveRegion="polite"
              className="absolute inset-0 items-center justify-center"
            >
              <Text className="text-sm text-muted-foreground">
                {active ? chartConfig[active].label : "Used"}
              </Text>
              <Text className="text-3xl font-semibold tracking-tight tabular-nums">
                {`${formatSize(activeValue)} GB`}
              </Text>
              <Text className="text-sm text-muted-foreground tabular-nums">
                {`${Math.round((activeValue / total) * 100)}%`}
              </Text>
            </View>
            <ChartContainer
              config={chartConfig}
              accessibilityLabel={`${STORAGE[device].label} storage`}
              className="aspect-square size-full"
            >
              <PieChart
                key={device}
                onActiveIndexChange={(index) =>
                  setActive(index === null ? null : (KINDS[index] ?? null))
                }
              >
                <Pie
                  isAnimationActive={false}
                  data={data}
                  dataKey="size"
                  nameKey="kind"
                  innerRadius="64%"
                  outerRadius="88%"
                  startAngle={90}
                  endAngle={-270}
                  stroke="muted"
                  strokeWidth={3}
                  cornerRadius={4}
                  shape={(sector, index) => ({
                    ...sector,
                    outerRadius:
                      sector.outerRadius + (KINDS[index] === active ? LIFT : 0),
                  })}
                />
              </PieChart>
            </ChartContainer>
          </View>
          <View className="min-w-60 grow basis-60">
            {KINDS.filter((kind) => sizeOf(kind) > 0).map((kind) => (
              <Pressable
                key={kind}
                role="button"
                accessibilityState={{ selected: active === kind }}
                onPress={() =>
                  setActive((current) => (current === kind ? null : kind))
                }
                className={cn(
                  "flex-row items-center gap-2.5 rounded-lg px-2 py-2.25",
                  active === kind && "bg-secondary"
                )}
              >
                <View
                  className={cn("size-2.5 shrink-0 rounded-full", SWATCH[kind])}
                />
                <Text className="grow text-base">
                  {chartConfig[kind].label}
                </Text>
                <Text className="text-base text-muted-foreground tabular-nums">
                  {`${formatSize(Math.max(0, sizeOf(kind)))} GB`}
                </Text>
              </Pressable>
            ))}
          </View>
        </View>
      </CardContent>
    </Card>
  )
}
```

```swift title="swift/Charts/PieChartInteractive.swift"
import Charts
import SwiftUI

private enum Device: String, CaseIterable {
  case phone, cloud

  var label: String {
    switch self {
    case .phone: "Phone"
    case .cloud: "Cloud"
    }
  }

  var total: Double {
    switch self {
    case .phone: 256
    case .cloud: 200
    }
  }

  var used: [String: Double] {
    switch self {
    case .phone: ["apps": 62.4, "photos": 48.1, "system": 25.8, "messages": 9.8, "other": 6.3]
    case .cloud: ["photos": 96.2, "backups": 31.4, "drive": 18.7, "messages": 7.9, "mail": 2.3]
    }
  }

  var sizes: [Double] {
    let taken = used.values.reduce(0, +)
    return kinds.map { $0 == "free" ? total - taken : used[$0] ?? 0 }
  }
}

private let kinds = ["apps", "photos", "system", "backups", "drive", "messages", "mail", "other", "free"]

private let chartConfig: ChartConfig = [
  "apps": .init("Apps", color: Palette.red500),
  "photos": .init("Photos", color: EsuissColor.chart4),
  "system": .init("System", color: EsuissColor.chart5),
  "backups": .init("Backups", color: Palette.purple500),
  "drive": .init("Drive", color: EsuissColor.chart1),
  "messages": .init("Messages", color: Palette.green500),
  "mail": .init("Mail", color: Palette.cyan500),
  "other": .init("Other", color: Palette.yellow500),
  "free": .init("Free", color: EsuissColor.secondary),
]

public struct PieChartInteractive: View {
  @State private var device: Device = .phone
  @State private var active: Int?
  @Environment(\.locale) private var locale
  @Environment(\.accessibilityReduceMotion) private var reduceMotion

  public init() {}

  private var deviceBinding: Binding<Device?> {
    Binding(
      get: { device },
      set: { value in
        guard let value, value != device else { return }
        withAnimation(reduceMotion ? nil : .timingCurve(0.65, 0, 0.35, 1, duration: 0.7)) {
          device = value
          active = nil
        }
      }
    )
  }

  private var activeBinding: Binding<Int?> {
    Binding(
      get: { active },
      set: { value in
        withAnimation(reduceMotion ? nil : .easeOut(duration: 0.26)) { active = value }
      }
    )
  }

  private func size(_ value: Double) -> String {
    max(0, value).formatted(.number.precision(.fractionLength(1)).locale(locale))
  }

  private func gigabytes(_ value: Double) -> String {
    "\(size(value)) GB"
  }

  public var body: some View {
    let sizes = device.sizes
    let total = sizes.reduce(0, +)
    let used = total - (sizes.last ?? 0)
    let value = active.map { sizes[$0] } ?? used
    Card(.filled, size: .sm) {
      HStack(alignment: .top, spacing: 16) {
        VStack(alignment: .leading, spacing: 2) {
          Text("\(device.label) storage")
            .textStyle(.lg, weight: .semibold)
          Text("\(size(used)) GB of \(Int(device.total)) GB used")
            .textStyle(.sm)
            .monospacedDigit()
            .foregroundStyle(EsuissColor.mutedForeground)
        }
        .frame(maxWidth: .infinity, alignment: .leading)
        ToggleGroup(selection: deviceBinding, size: .sm, spacing: 0) {
          ForEach(Device.allCases, id: \.self) { item in
            ToggleGroupItem(LocalizedStringKey(item.label), value: item)
          }
        }
        .accessibilityLabel("Device")
      }
      .padding(.horizontal, 16)
      CardContent {
        VStack(spacing: 20) {
          storageBar(sizes: sizes, total: total)
          ChartContainer(config: chartConfig) {
            Chart {
              ForEach(kinds.indices, id: \.self) { index in
                SectorMark(
                  angle: .value("Size", sizes[index]),
                  innerRadius: .ratio(0.62),
                  outerRadius: .ratio(index == active ? 0.9 : 0.85),
                  angularInset: 1.5
                )
                .cornerRadius(4)
                .foregroundStyle(chartConfig.color(kinds[index]))
              }
            }
            .background {
              VStack(spacing: 0) {
                Text(LocalizedStringKey(active.map { chartConfig.label(kinds[$0]) } ?? "Used"))
                  .textStyle(.sm)
                  .foregroundStyle(EsuissColor.mutedForeground)
                Text(verbatim: gigabytes(value))
                  .textStyle(.xl3, weight: .semibold)
                  .monospacedDigit()
                  .lineLimit(1)
                  .minimumScaleFactor(0.6)
                  .frame(maxWidth: 124)
                  .contentTransition(.numericText(value: value))
                Text(verbatim: "\(Int((value / max(total, 1) * 100).rounded()))%")
                  .textStyle(.sm)
                  .monospacedDigit()
                  .foregroundStyle(EsuissColor.mutedForeground)
              }
              .multilineTextAlignment(.center)
            }
            .chartTooltip(
              angle: sizes,
              labels: kinds.map { chartConfig.label($0) },
              innerRadius: 0.62,
              outerRadius: 0.9,
              selection: activeBinding,
              accessibilityLabel: "\(device.label) storage",
              items: { [ChartTooltipItem(kinds[$0], value: (sizes[$0] * 10).rounded() / 10)] }
            ) { _ in
              EmptyView()
            }
            .padding(5)
          }
          .frame(width: 280, height: 280)
          VStack(spacing: 0) {
            ForEach(kinds.indices, id: \.self) { index in
              if sizes[index] > 0 {
                row(index, value: sizes[index])
                  .transition(.opacity)
              }
            }
          }
        }
      }
    }
  }

  private func storageBar(sizes: [Double], total: Double) -> some View {
    GeometryReader { geometry in
      HStack(spacing: 0) {
        ForEach(kinds.indices.dropLast(), id: \.self) { index in
          let share = max(0, sizes[index]) / max(total, 1)
          Rectangle()
            .fill(chartConfig.color(kinds[index]))
            .opacity(active == nil || active == index ? 1 : 0.35)
            .frame(width: geometry.size.width * share)
            .padding(.trailing, min(2, share * 400))
        }
      }
    }
    .frame(height: 10)
    .background(EsuissColor.secondary)
    .clipShape(Capsule())
    .accessibilityHidden(true)
  }

  private func row(_ index: Int, value: Double) -> some View {
    let kind = kinds[index]
    return Button {
      activeBinding.wrappedValue = active == index ? nil : index
    } label: {
      HStack(spacing: 10) {
        Circle()
          .fill(chartConfig.color(kind))
          .overlay {
            if kind == "free" {
              Circle().strokeBorder(EsuissColor.input, lineWidth: 1)
            }
          }
          .frame(width: 10, height: 10)
        Text(LocalizedStringKey(chartConfig.label(kind)))
          .textStyle(.base)
          .foregroundStyle(EsuissColor.foreground)
          .frame(maxWidth: .infinity, alignment: .leading)
        Text(verbatim: gigabytes(value))
          .textStyle(.base)
          .monospacedDigit()
          .foregroundStyle(EsuissColor.mutedForeground)
      }
      .padding(.horizontal, 8)
      .padding(.vertical, 9)
      .background(active == index ? EsuissColor.secondary : .clear, in: RoundedRectangle(cornerRadius: Radius.lg, style: .continuous))
      .contentShape(Rectangle())
    }
    .buttonStyle(.plain)
    .accessibilityAddTraits(active == index ? .isSelected : [])
  }
}
```

```kt title="kotlin/charts/PieChartInteractive.kt"
package com.esuiss.ui.charts

import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.core.CubicBezierEasing
import androidx.compose.animation.core.animateFloatAsState
import androidx.compose.animation.core.snap
import androidx.compose.animation.core.tween
import androidx.compose.animation.expandVertically
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.animation.shrinkVertically
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.clickable
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.widthIn
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.text.BasicText
import androidx.compose.runtime.Composable
import androidx.compose.runtime.State
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.graphicsLayer
import androidx.compose.ui.layout.Layout
import androidx.compose.ui.semantics.LiveRegionMode
import androidx.compose.ui.semantics.Role
import androidx.compose.ui.semantics.clearAndSetSemantics
import androidx.compose.ui.semantics.contentDescription
import androidx.compose.ui.semantics.liveRegion
import androidx.compose.ui.semantics.selected
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.Constraints
import androidx.compose.ui.unit.dp
import com.esuiss.ui.components.Card
import com.esuiss.ui.components.CardContent
import com.esuiss.ui.components.CardSize
import com.esuiss.ui.components.CardVariant
import com.esuiss.ui.components.ChartConfig
import com.esuiss.ui.components.ChartConfigItem
import com.esuiss.ui.components.ChartContainer
import com.esuiss.ui.components.ChartSector
import com.esuiss.ui.components.PieChart
import com.esuiss.ui.components.ToggleGroup
import com.esuiss.ui.components.ToggleGroupItem
import com.esuiss.ui.components.ToggleSize
import com.esuiss.ui.components.formReducedMotion
import com.esuiss.ui.theme.EsuissTheme
import com.esuiss.ui.theme.Palette
import com.esuiss.ui.theme.Radius
import com.esuiss.ui.theme.Typography
import java.util.Locale
import kotlin.math.max
import kotlin.math.min
import kotlin.math.roundToInt

private class PieInteractiveStorage(val label: String, val total: Double, val used: Map<String, Double>)

private val kinds = listOf("apps", "photos", "system", "backups", "drive", "messages", "mail", "other", "free")

private val storage = linkedMapOf(
    "phone" to PieInteractiveStorage(
        "Phone",
        256.0,
        mapOf("apps" to 62.4, "photos" to 48.1, "system" to 25.8, "messages" to 9.8, "other" to 6.3),
    ),
    "cloud" to PieInteractiveStorage(
        "Cloud",
        200.0,
        mapOf("photos" to 96.2, "backups" to 31.4, "drive" to 18.7, "messages" to 7.9, "mail" to 2.3),
    ),
)

private val chartConfig = ChartConfig(
    "apps" to ChartConfigItem("Apps") { Palette.red500 },
    "photos" to ChartConfigItem("Photos") { chart4 },
    "system" to ChartConfigItem("System") { chart5 },
    "backups" to ChartConfigItem("Backups") { Palette.purple500 },
    "drive" to ChartConfigItem("Drive") { chart1 },
    "messages" to ChartConfigItem("Messages") { Palette.green500 },
    "mail" to ChartConfigItem("Mail") { Palette.cyan500 },
    "other" to ChartConfigItem("Other") { Palette.yellow500 },
    "free" to ChartConfigItem("Free") { secondary },
)

private val MorphEasing = CubicBezierEasing(0.65f, 0f, 0.35f, 1f)

private fun sizes(device: String): List<Double> {
    val entry = storage.getValue(device)
    val taken = entry.used.values.sum()
    return kinds.map { if (it == "free") entry.total - taken else entry.used[it] ?: 0.0 }
}

private fun gigabytes(value: Double) = String.format(Locale.US, "%.1f", max(0.0, value))

@Composable
fun PieChartInteractive(modifier: Modifier = Modifier) {
    val colors = EsuissTheme.colors
    val reduced = formReducedMotion()
    var device by remember { mutableStateOf("phone") }
    var active by remember { mutableStateOf<Int?>(null) }
    val target = sizes(device)
    val values: List<State<Float>> = kinds.indices.map { index ->
        animateFloatAsState(
            target[index].toFloat(),
            if (reduced) snap() else tween(700, easing = MorphEasing),
            label = "size",
        )
    }
    val lifts: List<State<Float>> = kinds.indices.map { index ->
        animateFloatAsState(
            if (active == index) 1f else 0f,
            if (reduced) snap() else tween(260, easing = MorphEasing),
            label = "lift",
        )
    }
    val sizes = values.map { it.value.toDouble() }
    val total = sizes.sum()
    val used = total - sizes.last()
    val value = active?.let { sizes[it] } ?: used
    val swatch = { kind: String -> chartConfig[kind]?.color?.invoke(colors) ?: colors.mutedForeground }
    Card(modifier, variant = CardVariant.Filled, size = CardSize.Sm) {
        CardContent {
            Row(horizontalArrangement = Arrangement.spacedBy(16.dp), verticalAlignment = Alignment.Top) {
                Column(Modifier.weight(1f), verticalArrangement = Arrangement.spacedBy(2.dp)) {
                    BasicText(
                        "${storage.getValue(device).label} storage",
                        style = Typography.lg.copy(color = colors.foreground, fontWeight = FontWeight.SemiBold),
                    )
                    BasicText(
                        "${gigabytes(target.sum() - target.last())} GB of ${storage.getValue(device).total.toInt()} GB used",
                        style = Typography.sm.copy(color = colors.mutedForeground, fontFeatureSettings = "tnum"),
                    )
                }
                ToggleGroup(
                    value = device,
                    onValueChange = { next ->
                        if (next != null) {
                            device = next
                            active = null
                        }
                    },
                    modifier = Modifier.semantics { contentDescription = "Device" },
                    size = ToggleSize.Sm,
                    spacing = 0,
                ) {
                    for ((key, entry) in storage) ToggleGroupItem(entry.label, key)
                }
            }
        }
        CardContent(Modifier.padding(top = 20.dp)) {
            Column(verticalArrangement = Arrangement.spacedBy(20.dp)) {
                StorageBar(sizes, total, active)
                Box(
                    Modifier
                        .align(Alignment.CenterHorizontally)
                        .size(280.dp),
                ) {
                    ChartContainer(chartConfig, Modifier.matchParentSize()) {
                        PieChart(
                            accessibilityLabel = "${storage.getValue(device).label} storage",
                            selectedIndex = active,
                            onSelectedIndexChange = { active = it },
                        ) {
                            Pie(
                                kinds.indices.toList(),
                                value = { max(0.0, sizes[it]) },
                                nameKey = { kinds[it] },
                                innerRadius = 0.64f,
                                outerRadius = 0.88f,
                                startAngle = 90f,
                                endAngle = -270f,
                                stroke = colors.muted,
                                strokeWidth = 3.dp,
                                cornerRadius = 4.dp,
                                sectors = { index -> ChartSector(lift = 7.dp * lifts[index].value) },
                                isAnimationActive = false,
                            )
                        }
                    }
                    Column(
                        Modifier
                            .align(Alignment.Center)
                            .widthIn(max = 160.dp)
                            .semantics { liveRegion = LiveRegionMode.Polite },
                        horizontalAlignment = Alignment.CenterHorizontally,
                    ) {
                        BasicText(
                            active?.let { chartConfig[kinds[it]]?.label } ?: "Used",
                            style = Typography.sm.copy(color = colors.mutedForeground),
                        )
                        BasicText(
                            "${gigabytes(value)} GB",
                            style = Typography.xl3.copy(color = colors.foreground, fontWeight = FontWeight.SemiBold, fontFeatureSettings = "tnum"),
                            maxLines = 1,
                        )
                        BasicText(
                            "${(value / max(total, 1.0) * 100).roundToInt()}%",
                            style = Typography.sm.copy(color = colors.mutedForeground, fontFeatureSettings = "tnum"),
                        )
                    }
                }
                Column {
                    kinds.forEachIndexed { index, kind ->
                        AnimatedVisibility(
                            visible = target[index] > 0,
                            enter = fadeIn(tween(500)) + expandVertically(tween(500, easing = MorphEasing)),
                            exit = fadeOut(tween(500)) + shrinkVertically(tween(500, easing = MorphEasing)),
                        ) {
                            StorageRow(
                                label = chartConfig[kind]?.label ?: kind,
                                value = "${gigabytes(sizes[index])} GB",
                                color = swatch(kind),
                                free = kind == "free",
                                selected = active == index,
                                onClick = { active = if (active == index) null else index },
                            )
                        }
                    }
                }
            }
        }
    }
}

@Composable
private fun StorageBar(sizes: List<Double>, total: Double, active: Int?) {
    val colors = EsuissTheme.colors
    Layout(
        content = {
            kinds.indices.toList().dropLast(1).forEach { index ->
                Box(
                    Modifier
                        .fillMaxHeight()
                        .graphicsLayer { alpha = if (active == null || active == index) 1f else 0.35f }
                        .background(chartConfig[kinds[index]]?.color?.invoke(colors) ?: colors.mutedForeground),
                )
            }
        },
        modifier = Modifier
            .fillMaxWidth()
            .height(10.dp)
            .clip(CircleShape)
            .background(colors.secondary)
            .clearAndSetSemantics {},
    ) { measurables, constraints ->
        val width = constraints.maxWidth
        val height = constraints.maxHeight
        var x = 0f
        val placed = measurables.mapIndexed { index, measurable ->
            val share = max(0.0, sizes[index]) / max(total, 1.0)
            val w = (width * share).toFloat()
            val placeable = measurable.measure(Constraints.fixed(w.roundToInt().coerceAtLeast(0), height))
            val start = x
            x += w + min(2.dp.toPx(), (share * 400).toFloat().dp.toPx())
            placeable to start
        }
        layout(width, height) {
            for ((placeable, start) in placed) placeable.place(start.roundToInt(), 0)
        }
    }
}

@Composable
private fun StorageRow(
    label: String,
    value: String,
    color: Color,
    free: Boolean,
    selected: Boolean,
    onClick: () -> Unit,
) {
    val colors = EsuissTheme.colors
    val shape = RoundedCornerShape(Radius.lg)
    Row(
        Modifier
            .fillMaxWidth()
            .clip(shape)
            .background(if (selected) colors.secondary else Color.Transparent, shape)
            .clickable(
                interactionSource = remember { MutableInteractionSource() },
                indication = null,
                role = Role.Button,
                onClick = onClick,
            )
            .semantics { this.selected = selected }
            .padding(horizontal = 8.dp, vertical = 9.dp),
        horizontalArrangement = Arrangement.spacedBy(10.dp),
        verticalAlignment = Alignment.CenterVertically,
    ) {
        Box(
            Modifier
                .size(10.dp)
                .background(color, CircleShape)
                .then(if (free) Modifier.border(1.dp, colors.input, CircleShape) else Modifier),
        )
        BasicText(
            label,
            Modifier.weight(1f),
            style = Typography.base.copy(color = colors.foreground),
            maxLines = 1,
            overflow = TextOverflow.Ellipsis,
        )
        BasicText(value, style = Typography.base.copy(color = colors.mutedForeground, fontFeatureSettings = "tnum"))
    }
}
```

**React Native**

A `Card` with a `ToggleGroup` that switches between phone and cloud storage, a stacked usage bar, a `PieChart` donut and a list of categories. Sizes come from the `STORAGE` record, and free space is the total minus what is used. Pressing a slice or a list row selects that category: its slice lifts outward, other segments in the bar dim, and the center text shows its size and share. Pressing it again returns to total used. The donut sets `isAnimationActive={false}` and draws without the enter animation.

Replace `STORAGE` with your devices, totals and per-category sizes, and keep `KINDS`, `chartConfig` and `SWATCH` in sync when adding categories. The component takes no props.

**React Native, SwiftUI, Jetpack Compose**

### Installation

**Command**

**React Native**

```bash title="Terminal"
npx shadcn@latest add @esuiss/pie-chart-interactive
```

See [Installation](https://suiss.app/ui/docs/installation) for the `components.json` setup. Or use the [suiss/ui CLI](https://suiss.app/ui/docs/cli):

```bash title="Terminal"
npx @esuiss/ui@latest add charts pie-chart-interactive
```

**SwiftUI**

```bash title="Terminal"
npx shadcn@latest add @esuiss/pie-chart-interactive
```

See [Installation](https://suiss.app/ui/docs/installation) for the `components.json` setup. Or use the [suiss/ui CLI](https://suiss.app/ui/docs/cli):

```bash title="Terminal"
npx @esuiss/ui@latest add charts pie-chart-interactive --platform swift
```

**Jetpack Compose**

```bash title="Terminal"
npx shadcn@latest add @esuiss/pie-chart-interactive
```

See [Installation](https://suiss.app/ui/docs/installation) for the `components.json` setup. Or use the [suiss/ui CLI](https://suiss.app/ui/docs/cli):

```bash title="Terminal"
npx @esuiss/ui@latest add charts pie-chart-interactive --platform kotlin
```

**React Native**

The CLI also adds what it builds on: [Card](https://suiss.app/ui/docs/components/card), [Chart](https://suiss.app/ui/docs/components/chart), [Text](https://suiss.app/ui/docs/components/text), [Toggle Group](https://suiss.app/ui/docs/components/toggle-group).

**React Native, SwiftUI, Jetpack Compose**

**Manual**

**React Native**

**Uniwind**

1. Install the following dependencies:

```bash title="Terminal"
npx expo install cn
```

2. Add the pieces it builds on: [Card](https://suiss.app/ui/docs/components/card), [Chart](https://suiss.app/ui/docs/components/chart), [Text](https://suiss.app/ui/docs/components/text), [Toggle Group](https://suiss.app/ui/docs/components/toggle-group).

3. Copy and paste the following code into `components/charts/pie-chart-interactive.tsx`:

- `uniwind/components/charts/pie-chart-interactive.tsx`: shown above

4. Update the import paths to match your project setup.

**NativeWind**

1. Install the following dependencies:

```bash title="Terminal"
npx expo install cn
```

2. Add the pieces it builds on: [Card](https://suiss.app/ui/docs/components/card), [Chart](https://suiss.app/ui/docs/components/chart), [Text](https://suiss.app/ui/docs/components/text), [Toggle Group](https://suiss.app/ui/docs/components/toggle-group).

3. Copy and paste the following code into `components/charts/pie-chart-interactive.tsx`:

```tsx title="nativewind/components/charts/pie-chart-interactive.tsx"
import { cn } from "cn"
import * as React from "react"
import { Pressable, View } from "react-native"
import { Card, CardContent, CardHeader } from "@/components/ui/card"
import {
  type ChartConfig,
  ChartContainer,
  Pie,
  PieChart,
} from "@/components/ui/chart"
import { Text } from "@/components/ui/text"
import { ToggleGroup, ToggleGroupItem } from "@/components/ui/toggle-group"

type Device = "phone" | "cloud"

type Kind =
  | "apps"
  | "photos"
  | "system"
  | "backups"
  | "drive"
  | "messages"
  | "mail"
  | "other"
  | "free"

const KINDS: Kind[] = [
  "apps",
  "photos",
  "system",
  "backups",
  "drive",
  "messages",
  "mail",
  "other",
  "free",
]

const STORAGE: Record<
  Device,
  { label: string; total: number; used: Partial<Record<Kind, number>> }
> = {
  phone: {
    label: "Phone",
    total: 256,
    used: { apps: 62.4, photos: 48.1, system: 25.8, messages: 9.8, other: 6.3 },
  },
  cloud: {
    label: "Cloud",
    total: 200,
    used: {
      photos: 96.2,
      backups: 31.4,
      drive: 18.7,
      messages: 7.9,
      mail: 2.3,
    },
  },
}

const chartConfig = {
  apps: { label: "Apps", color: "red-500" },
  photos: { label: "Photos", color: "chart-4" },
  system: { label: "System", color: "chart-5" },
  backups: { label: "Backups", color: "purple-500" },
  drive: { label: "Drive", color: "chart-1" },
  messages: { label: "Messages", color: "green-500" },
  mail: { label: "Mail", color: "cyan-500" },
  other: { label: "Other", color: "yellow-500" },
  free: { label: "Free", color: "secondary" },
} satisfies ChartConfig

const SWATCH: Record<Kind, string> = {
  apps: "bg-red-500",
  photos: "bg-orange-500",
  system: "bg-zinc-500",
  backups: "bg-purple-500",
  drive: "bg-blue-500",
  messages: "bg-green-500",
  mail: "bg-cyan-500",
  other: "bg-yellow-500",
  free: "bg-secondary border border-input",
}

const LIFT = 7

function formatSize(value: number) {
  try {
    return new Intl.NumberFormat("en-US", {
      minimumFractionDigits: 1,
      maximumFractionDigits: 1,
    }).format(value)
  } catch {
    return value.toFixed(1)
  }
}

function sizes(device: Device) {
  const { total, used } = STORAGE[device]
  const taken = Object.values(used).reduce((sum, value) => sum + value, 0)
  return KINDS.map((kind) =>
    kind === "free" ? total - taken : (used[kind] ?? 0)
  )
}

export function PieChartInteractive() {
  const [device, setDevice] = React.useState<Device>("phone")
  const [active, setActive] = React.useState<Kind | null>(null)
  const values = React.useMemo(() => sizes(device), [device])
  const sizeOf = (kind: Kind) => values[KINDS.indexOf(kind)] ?? 0
  const total = values.reduce((sum, value) => sum + value, 0)
  const used = total - sizeOf("free")
  const activeValue = active ? sizeOf(active) : used
  const data = KINDS.map((kind, index) => ({
    kind,
    size: Math.max(0, values[index] ?? 0),
  }))

  return (
    <Card variant="filled" size="sm">
      <CardHeader className="flex-row flex-wrap items-start justify-between gap-4">
        <View className="min-w-48 grow gap-0.5">
          <Text className="text-lg font-semibold">
            {`${STORAGE[device].label} storage`}
          </Text>
          <Text className="text-sm text-muted-foreground tabular-nums">
            {`${formatSize(used)} GB of ${STORAGE[device].total} GB used`}
          </Text>
        </View>
        <ToggleGroup
          spacing={0}
          value={[device]}
          onValueChange={(value) => {
            if (!value[0]) return
            setDevice(value[0] as Device)
            setActive(null)
          }}
          accessibilityLabel="Device"
        >
          {(Object.keys(STORAGE) as Device[]).map((key) => (
            <ToggleGroupItem key={key} value={key} size="sm" className="px-5">
              <Text>{STORAGE[key].label}</Text>
            </ToggleGroupItem>
          ))}
        </ToggleGroup>
      </CardHeader>
      <CardContent className="gap-5">
        <View
          accessibilityElementsHidden
          importantForAccessibility="no-hide-descendants"
          className="h-2.5 flex-row overflow-hidden rounded-full bg-secondary"
        >
          {KINDS.filter((kind) => kind !== "free").map((kind) => {
            const share = (Math.max(0, sizeOf(kind)) / total) * 100
            return (
              <View
                key={kind}
                style={{
                  width: `${share}%`,
                  marginEnd: Math.min(2, share * 4),
                }}
                className={cn(
                  "h-full",
                  SWATCH[kind],
                  active && active !== kind && "opacity-35"
                )}
              />
            )
          })}
        </View>
        <View className="flex-row flex-wrap items-center justify-center gap-6">
          <View className="size-[17.5rem] max-w-full">
            <View
              pointerEvents="none"
              accessibilityLiveRegion="polite"
              className="absolute inset-0 items-center justify-center"
            >
              <Text className="text-sm text-muted-foreground">
                {active ? chartConfig[active].label : "Used"}
              </Text>
              <Text className="text-3xl font-semibold tracking-tight tabular-nums">
                {`${formatSize(activeValue)} GB`}
              </Text>
              <Text className="text-sm text-muted-foreground tabular-nums">
                {`${Math.round((activeValue / total) * 100)}%`}
              </Text>
            </View>
            <ChartContainer
              config={chartConfig}
              accessibilityLabel={`${STORAGE[device].label} storage`}
              className="aspect-square size-full"
            >
              <PieChart
                key={device}
                onActiveIndexChange={(index) =>
                  setActive(index === null ? null : (KINDS[index] ?? null))
                }
              >
                <Pie
                  isAnimationActive={false}
                  data={data}
                  dataKey="size"
                  nameKey="kind"
                  innerRadius="64%"
                  outerRadius="88%"
                  startAngle={90}
                  endAngle={-270}
                  stroke="muted"
                  strokeWidth={3}
                  cornerRadius={4}
                  shape={(sector, index) => ({
                    ...sector,
                    outerRadius:
                      sector.outerRadius + (KINDS[index] === active ? LIFT : 0),
                  })}
                />
              </PieChart>
            </ChartContainer>
          </View>
          <View className="min-w-60 grow basis-60">
            {KINDS.filter((kind) => sizeOf(kind) > 0).map((kind) => (
              <Pressable
                key={kind}
                role="button"
                accessibilityState={{ selected: active === kind }}
                onPress={() =>
                  setActive((current) => (current === kind ? null : kind))
                }
                className={cn(
                  "flex-row items-center gap-2.5 rounded-lg px-2 py-[0.5625rem]",
                  active === kind && "bg-secondary"
                )}
              >
                <View
                  className={cn("size-2.5 shrink-0 rounded-full", SWATCH[kind])}
                />
                <Text className="grow text-base">
                  {chartConfig[kind].label}
                </Text>
                <Text className="text-base text-muted-foreground tabular-nums">
                  {`${formatSize(Math.max(0, sizeOf(kind)))} GB`}
                </Text>
              </Pressable>
            ))}
          </View>
        </View>
      </CardContent>
    </Card>
  )
}
```

4. Update the import paths to match your project setup.

**StyleSheet**

1. Add the pieces it builds on: [Card](https://suiss.app/ui/docs/components/card), [Chart](https://suiss.app/ui/docs/components/chart), [Text](https://suiss.app/ui/docs/components/text), [Toggle Group](https://suiss.app/ui/docs/components/toggle-group).

2. Copy and paste the following code into `components/charts/pie-chart-interactive.tsx`:

```tsx title="stylesheet/components/charts/pie-chart-interactive.tsx"
import * as React from "react"
import { Pressable, StyleSheet, View } from "react-native"
import { Card, CardContent, CardHeader } from "@/components/ui/card"
import {
  type ChartConfig,
  ChartContainer,
  Pie,
  PieChart,
} from "@/components/ui/chart"
import { Text } from "@/components/ui/text"
import {
  fontSize,
  palette,
  type ThemeColors,
  useTheme,
} from "@/components/ui/theme"

import { ToggleGroup, ToggleGroupItem } from "@/components/ui/toggle-group"

type Tone = keyof ThemeColors | keyof typeof palette

function tone(colors: ThemeColors, key: Tone) {
  return { ...colors, ...palette }[key]
}

type Device = "phone" | "cloud"

type Kind =
  | "apps"
  | "photos"
  | "system"
  | "backups"
  | "drive"
  | "messages"
  | "mail"
  | "other"
  | "free"

const KINDS: Kind[] = [
  "apps",
  "photos",
  "system",
  "backups",
  "drive",
  "messages",
  "mail",
  "other",
  "free",
]

const STORAGE: Record<
  Device,
  { label: string; total: number; used: Partial<Record<Kind, number>> }
> = {
  phone: {
    label: "Phone",
    total: 256,
    used: { apps: 62.4, photos: 48.1, system: 25.8, messages: 9.8, other: 6.3 },
  },
  cloud: {
    label: "Cloud",
    total: 200,
    used: {
      photos: 96.2,
      backups: 31.4,
      drive: 18.7,
      messages: 7.9,
      mail: 2.3,
    },
  },
}

const chartConfig = {
  apps: { label: "Apps", color: "red-500" },
  photos: { label: "Photos", color: "chart-4" },
  system: { label: "System", color: "chart-5" },
  backups: { label: "Backups", color: "purple-500" },
  drive: { label: "Drive", color: "chart-1" },
  messages: { label: "Messages", color: "green-500" },
  mail: { label: "Mail", color: "cyan-500" },
  other: { label: "Other", color: "yellow-500" },
  free: { label: "Free", color: "secondary" },
} satisfies ChartConfig

const SWATCH: Record<Kind, Tone> = {
  apps: "red500",
  photos: "chart4",
  system: "chart5",
  backups: "purple500",
  drive: "chart1",
  messages: "green500",
  mail: "cyan500",
  other: "yellow500",
  free: "secondary",
}

const styles = StyleSheet.create({
  header: {
    flexDirection: "row",
    flexWrap: "wrap",
    alignItems: "flex-start",
    justifyContent: "space-between",
    gap: 16,
  },
  heading: { minWidth: 192, flexGrow: 1, gap: 2 },
  title: { ...fontSize.lg, fontWeight: "600" },
  caption: { ...fontSize.sm, fontVariant: ["tabular-nums"] },
  device: { paddingHorizontal: 20 },
  content: { gap: 20 },
  bar: {
    height: 10,
    flexDirection: "row",
    overflow: "hidden",
    borderRadius: 9999,
  },
  segment: { height: "100%" },
  dimmed: { opacity: 0.35 },
  body: {
    flexDirection: "row",
    flexWrap: "wrap",
    alignItems: "center",
    justifyContent: "center",
    gap: 24,
  },
  pie: { width: 280, height: 280, maxWidth: "100%" },
  center: {
    ...StyleSheet.absoluteFill,
    alignItems: "center",
    justifyContent: "center",
  },
  value: {
    ...fontSize["3xl"],
    fontWeight: "600",
    letterSpacing: -0.75,
    fontVariant: ["tabular-nums"],
  },
  chart: { width: "100%", height: "100%", aspectRatio: 1 },
  list: { minWidth: 240, flexGrow: 1, flexBasis: 240 },
  row: {
    flexDirection: "row",
    alignItems: "center",
    gap: 10,
    borderRadius: 8,
    paddingHorizontal: 8,
    paddingVertical: 9,
  },
  dot: { width: 10, height: 10, flexShrink: 0, borderRadius: 9999 },
  name: { flexGrow: 1, ...fontSize.base },
  size: { ...fontSize.base, fontVariant: ["tabular-nums"] },
})

const LIFT = 7

function formatSize(value: number) {
  try {
    return new Intl.NumberFormat("en-US", {
      minimumFractionDigits: 1,
      maximumFractionDigits: 1,
    }).format(value)
  } catch {
    return value.toFixed(1)
  }
}

function sizes(device: Device) {
  const { total, used } = STORAGE[device]
  const taken = Object.values(used).reduce((sum, value) => sum + value, 0)
  return KINDS.map((kind) =>
    kind === "free" ? total - taken : (used[kind] ?? 0)
  )
}

export function PieChartInteractive() {
  const { colors } = useTheme()
  const [device, setDevice] = React.useState<Device>("phone")
  const [active, setActive] = React.useState<Kind | null>(null)
  const values = React.useMemo(() => sizes(device), [device])
  const sizeOf = (kind: Kind) => values[KINDS.indexOf(kind)] ?? 0
  const total = values.reduce((sum, value) => sum + value, 0)
  const used = total - sizeOf("free")
  const activeValue = active ? sizeOf(active) : used
  const data = KINDS.map((kind, index) => ({
    kind,
    size: Math.max(0, values[index] ?? 0),
  }))

  return (
    <Card variant="filled" size="sm">
      <CardHeader style={styles.header}>
        <View style={styles.heading}>
          <Text style={styles.title}>{`${STORAGE[device].label} storage`}</Text>
          <Text style={[styles.caption, { color: colors.mutedForeground }]}>
            {`${formatSize(used)} GB of ${STORAGE[device].total} GB used`}
          </Text>
        </View>
        <ToggleGroup
          spacing={0}
          value={[device]}
          onValueChange={(value) => {
            if (!value[0]) return
            setDevice(value[0] as Device)
            setActive(null)
          }}
          accessibilityLabel="Device"
        >
          {(Object.keys(STORAGE) as Device[]).map((key) => (
            <ToggleGroupItem
              key={key}
              value={key}
              size="sm"
              style={styles.device}
            >
              <Text>{STORAGE[key].label}</Text>
            </ToggleGroupItem>
          ))}
        </ToggleGroup>
      </CardHeader>
      <CardContent style={styles.content}>
        <View
          accessibilityElementsHidden
          importantForAccessibility="no-hide-descendants"
          style={[styles.bar, { backgroundColor: colors.secondary }]}
        >
          {KINDS.filter((kind) => kind !== "free").map((kind) => {
            const share = (Math.max(0, sizeOf(kind)) / total) * 100
            return (
              <View
                key={kind}
                style={[
                  styles.segment,
                  {
                    width: `${share}%`,
                    marginEnd: Math.min(2, share * 4),
                    backgroundColor: tone(colors, SWATCH[kind]),
                  },
                  active && active !== kind && styles.dimmed,
                ]}
              />
            )
          })}
        </View>
        <View style={styles.body}>
          <View style={styles.pie}>
            <View
              pointerEvents="none"
              accessibilityLiveRegion="polite"
              style={styles.center}
            >
              <Text style={[styles.caption, { color: colors.mutedForeground }]}>
                {active ? chartConfig[active].label : "Used"}
              </Text>
              <Text style={styles.value}>
                {`${formatSize(activeValue)} GB`}
              </Text>
              <Text style={[styles.caption, { color: colors.mutedForeground }]}>
                {`${Math.round((activeValue / total) * 100)}%`}
              </Text>
            </View>
            <ChartContainer
              config={chartConfig}
              accessibilityLabel={`${STORAGE[device].label} storage`}
              style={styles.chart}
            >
              <PieChart
                key={device}
                onActiveIndexChange={(index) =>
                  setActive(index === null ? null : (KINDS[index] ?? null))
                }
              >
                <Pie
                  isAnimationActive={false}
                  data={data}
                  dataKey="size"
                  nameKey="kind"
                  innerRadius="64%"
                  outerRadius="88%"
                  startAngle={90}
                  endAngle={-270}
                  stroke="muted"
                  strokeWidth={3}
                  cornerRadius={4}
                  shape={(sector, index) => ({
                    ...sector,
                    outerRadius:
                      sector.outerRadius + (KINDS[index] === active ? LIFT : 0),
                  })}
                />
              </PieChart>
            </ChartContainer>
          </View>
          <View style={styles.list}>
            {KINDS.filter((kind) => sizeOf(kind) > 0).map((kind) => (
              <Pressable
                key={kind}
                role="button"
                accessibilityState={{ selected: active === kind }}
                onPress={() =>
                  setActive((current) => (current === kind ? null : kind))
                }
                style={[
                  styles.row,
                  active === kind && { backgroundColor: colors.secondary },
                ]}
              >
                <View
                  style={[
                    styles.dot,
                    { backgroundColor: tone(colors, SWATCH[kind]) },
                    kind === "free" && {
                      borderWidth: 1,
                      borderColor: colors.input,
                    },
                  ]}
                />
                <Text style={styles.name}>{chartConfig[kind].label}</Text>
                <Text style={[styles.size, { color: colors.mutedForeground }]}>
                  {`${formatSize(Math.max(0, sizeOf(kind)))} GB`}
                </Text>
              </Pressable>
            ))}
          </View>
        </View>
      </CardContent>
    </Card>
  )
}
```

3. Update the import paths to match your project setup.

**SwiftUI**

1. Target iOS 17 or later.

2. Add the Swift package to your app:

```swift title="Package.swift"
.package(url: "https://github.com/phosphor-icons/swift", from: "2.1.0")
```

3. Copy the theme files every view uses:

- `swift/Theme/Theme.swift`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/swiftui/Sources/EsuissUI/Theme/Theme.swift)

- `swift/Theme/Tokens.swift`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/swiftui/Sources/EsuissUI/Theme/Tokens.swift)

4. Copy the source and every file it uses:

- `swift/Charts/PieChartInteractive.swift`: shown above

- `swift/Components/Button.swift`: see [Button](https://suiss.app/ui/docs/components/button.md)

- `swift/Components/ButtonGroup.swift`: see [Button Group](https://suiss.app/ui/docs/components/button-group.md)

- `swift/Components/Card.swift`: see [Card](https://suiss.app/ui/docs/components/card.md)

- `swift/Components/Chart.swift`: see [Chart](https://suiss.app/ui/docs/components/chart.md)

- `swift/Components/Checkbox.swift`: see [Checkbox](https://suiss.app/ui/docs/components/checkbox.md)

- `swift/Components/Field.swift`: see [Field](https://suiss.app/ui/docs/components/field.md)

- `swift/Components/Haptics.swift`: see [Haptics](https://suiss.app/ui/docs/components/haptics.md)

- `swift/Components/Item.swift`: see [Item](https://suiss.app/ui/docs/components/item.md)

- `swift/Components/Separator.swift`: see [Separator](https://suiss.app/ui/docs/components/separator.md)

- `swift/Components/Toggle.swift`: see [Toggle](https://suiss.app/ui/docs/components/toggle.md)

- `swift/Components/ToggleGroup.swift`: see [Toggle Group](https://suiss.app/ui/docs/components/toggle-group.md)

5. Add the files to your app target.

**Jetpack Compose**

1. Apply the Compose compiler plugin, enable Compose, set `compileSdk` to 37 or higher and `minSdk` to 24 or higher, and add the dependencies:

```kotlin title="build.gradle.kts"
plugins {
    id("org.jetbrains.kotlin.plugin.compose")
}

android {
    compileSdk = 37
    defaultConfig { minSdk = 24 }
    buildFeatures { compose = true }
}

dependencies {
    implementation(platform("androidx.compose:compose-bom:2026.09.00"))
    implementation("androidx.compose.foundation:foundation")
    implementation("androidx.compose.ui:ui")
    implementation("com.adamglin:phosphor-icon-android:1.0.0")
}
```

2. Copy the theme files every view uses:

- `kotlin/theme/Theme.kt`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/kotlin/ui/src/main/kotlin/com/esuiss/ui/theme/Theme.kt)

- `kotlin/theme/Tokens.kt`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/kotlin/ui/src/main/kotlin/com/esuiss/ui/theme/Tokens.kt)

3. Copy the source and every file it uses:

- `kotlin/charts/PieChartInteractive.kt`: shown above

- `kotlin/components/Card.kt`: see [Card](https://suiss.app/ui/docs/components/card.md)

- `kotlin/components/Chart.kt`: see [Chart](https://suiss.app/ui/docs/components/chart.md)

- `kotlin/components/Checkbox.kt`: see [Checkbox](https://suiss.app/ui/docs/components/checkbox.md)

- `kotlin/components/Content.kt`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/kotlin/ui/src/main/kotlin/com/esuiss/ui/components/Content.kt)

- `kotlin/components/Field.kt`: see [Field](https://suiss.app/ui/docs/components/field.md)

- `kotlin/components/FormSupport.kt`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/kotlin/ui/src/main/kotlin/com/esuiss/ui/components/FormSupport.kt)

- `kotlin/components/Haptics.kt`: see [Haptics](https://suiss.app/ui/docs/components/haptics.md)

- `kotlin/components/Icon.kt`: see [Icon](https://suiss.app/ui/docs/components/icon.md)

- `kotlin/components/Label.kt`: see [Label](https://suiss.app/ui/docs/components/label.md)

- `kotlin/components/Separator.kt`: see [Separator](https://suiss.app/ui/docs/components/separator.md)

- `kotlin/components/Toggle.kt`: see [Toggle](https://suiss.app/ui/docs/components/toggle.md)

- `kotlin/components/ToggleGroup.kt`: see [Toggle Group](https://suiss.app/ui/docs/components/toggle-group.md)

4. Update the `com.esuiss.ui` package names to match your project.

**React Native, SwiftUI, Jetpack Compose**

### Usage

**React Native**

```tsx
import { PieChartInteractive } from "@/components/charts/pie-chart-interactive"
```

```tsx
<PieChartInteractive />
```

**SwiftUI**

```swift
import SwiftUI

struct PieInteractiveExample: View {
  var body: some View {
    PieChartInteractive()
  }
}
```

**Jetpack Compose**

```kotlin
import androidx.compose.runtime.Composable
import com.esuiss.ui.charts.PieChartInteractive

@Composable
fun PieInteractiveExample() {
    PieChartInteractive()
}
```



## Pie Chart Label

A pie with each category name drawn outside its slice and joined by a leader line.

Source: https://suiss.app/ui/docs/charts/pie-chart#label

**React**

**Example**

```tsx title="components/charts/pie-chart-label.tsx"
"use client"

import { Pie, PieChart } from "recharts"

import {
  Card,
  CardContent,
  CardDescription,
  CardHeader,
  CardTitle,
} from "@/components/ui/card"
import {
  type ChartConfig,
  ChartContainer,
  ChartTooltip,
  ChartTooltipContent,
} from "@/components/ui/chart"

const chartData = [
  { device: "phone", users: 275, fill: "var(--color-phone)" },
  { device: "laptop", users: 200, fill: "var(--color-laptop)" },
  { device: "tablet", users: 187, fill: "var(--color-tablet)" },
  { device: "watch", users: 173, fill: "var(--color-watch)" },
  { device: "other", users: 90, fill: "var(--color-other)" },
]

const chartConfig = {
  users: { label: "Users" },
  phone: { label: "Phone", color: "var(--chart-1)" },
  laptop: { label: "Laptop", color: "var(--chart-2)" },
  tablet: { label: "Tablet", color: "var(--chart-3)" },
  watch: { label: "Watch", color: "var(--chart-4)" },
  other: { label: "Other", color: "var(--chart-5)" },
} satisfies ChartConfig

export function PieChartLabel() {
  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>Labeled</CardTitle>
        <CardDescription>Each name sits outside its slice</CardDescription>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          className="aspect-auto h-52 w-full"
        >
          <PieChart accessibilityLayer>
            <ChartTooltip
              cursor={false}
              content={<ChartTooltipContent hideLabel nameKey="device" />}
            />
            <Pie
              data={chartData}
              dataKey="users"
              nameKey="device"
              outerRadius="68%"
              stroke="var(--muted)"
              strokeWidth={2}
              labelLine={{ stroke: "var(--input)" }}
              label={({ x, y, cx, name }) => (
                <text
                  x={x}
                  y={y}
                  textAnchor={x > cx ? "start" : "end"}
                  dominantBaseline="central"
                  className="fill-foreground text-xs font-semibold"
                >
                  {chartConfig[name as keyof typeof chartConfig].label}
                </text>
              )}
            />
          </PieChart>
        </ChartContainer>
      </CardContent>
    </Card>
  )
}
```

A pie with each category name printed outside its slice and connected by a leader line. Use it when readers shouldn't have to match colors against a separate legend.

Replace `chartData` and the category entries in `chartConfig`; labels read their text from the config. Change what the custom `label` renderer returns to print values or percentages, and shrink `outerRadius` if long names get clipped. Outside labels collide when slices are thin, so keep the category count low.

### Installation

**Command**

```bash title="Terminal"
npx shadcn@latest add @esuiss/pie-chart-label
```

Works in any project with a `components.json`. See [Installation](https://suiss.app/ui/docs/installation#add-components) for the one-line registry setup. Or use the [suiss/ui CLI](https://suiss.app/ui/docs/cli):

```bash title="Terminal"
npx @esuiss/ui@latest add charts pie-chart-label
```

**Manual**

1. Install the following dependencies:

```bash title="Terminal"
npm install recharts
```

2. Add the pieces it builds on: [Card](https://suiss.app/ui/docs/components/card), [Chart](https://suiss.app/ui/docs/components/chart).

3. Copy and paste the following code into your project.

```tsx title="components/charts/pie-chart-label.tsx"
"use client"

import { Pie, PieChart } from "recharts"

import {
  Card,
  CardContent,
  CardDescription,
  CardHeader,
  CardTitle,
} from "@/components/ui/card"
import {
  type ChartConfig,
  ChartContainer,
  ChartTooltip,
  ChartTooltipContent,
} from "@/components/ui/chart"

const chartData = [
  { device: "phone", users: 275, fill: "var(--color-phone)" },
  { device: "laptop", users: 200, fill: "var(--color-laptop)" },
  { device: "tablet", users: 187, fill: "var(--color-tablet)" },
  { device: "watch", users: 173, fill: "var(--color-watch)" },
  { device: "other", users: 90, fill: "var(--color-other)" },
]

const chartConfig = {
  users: { label: "Users" },
  phone: { label: "Phone", color: "var(--chart-1)" },
  laptop: { label: "Laptop", color: "var(--chart-2)" },
  tablet: { label: "Tablet", color: "var(--chart-3)" },
  watch: { label: "Watch", color: "var(--chart-4)" },
  other: { label: "Other", color: "var(--chart-5)" },
} satisfies ChartConfig

export function PieChartLabel() {
  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>Labeled</CardTitle>
        <CardDescription>Each name sits outside its slice</CardDescription>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          className="aspect-auto h-52 w-full"
        >
          <PieChart accessibilityLayer>
            <ChartTooltip
              cursor={false}
              content={<ChartTooltipContent hideLabel nameKey="device" />}
            />
            <Pie
              data={chartData}
              dataKey="users"
              nameKey="device"
              outerRadius="68%"
              stroke="var(--muted)"
              strokeWidth={2}
              labelLine={{ stroke: "var(--input)" }}
              label={({ x, y, cx, name }) => (
                <text
                  x={x}
                  y={y}
                  textAnchor={x > cx ? "start" : "end"}
                  dominantBaseline="central"
                  className="fill-foreground text-xs font-semibold"
                >
                  {chartConfig[name as keyof typeof chartConfig].label}
                </text>
              )}
            />
          </PieChart>
        </ChartContainer>
      </CardContent>
    </Card>
  )
}
```

4. Update the import paths to match your project setup.

### Usage

```tsx
import { PieChartLabel } from "@/components/charts/pie-chart-label"
```

```tsx
<PieChartLabel />
```

**React Native, SwiftUI, Jetpack Compose**

```tsx title="uniwind/components/charts/pie-chart-label.tsx"
import {
  Card,
  CardContent,
  CardDescription,
  CardHeader,
  CardTitle,
} from "@/components/ui/card"
import {
  type ChartConfig,
  ChartContainer,
  ChartTooltip,
  ChartTooltipContent,
  Pie,
  PieChart,
} from "@/components/ui/chart"

const chartData = [
  { device: "phone", users: 275 },
  { device: "laptop", users: 200 },
  { device: "tablet", users: 187 },
  { device: "watch", users: 173 },
  { device: "other", users: 90 },
]

const chartConfig = {
  users: { label: "Users" },
  phone: { label: "Phone", color: "chart-1" },
  laptop: { label: "Laptop", color: "chart-2" },
  tablet: { label: "Tablet", color: "chart-3" },
  watch: { label: "Watch", color: "chart-4" },
  other: { label: "Other", color: "chart-5" },
} satisfies ChartConfig

export function PieChartLabel() {
  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>Labeled</CardTitle>
        <CardDescription>Each name sits outside its slice</CardDescription>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          accessibilityLabel="Labeled"
          className="h-52 w-full"
        >
          <PieChart>
            <ChartTooltip
              cursor={false}
              content={<ChartTooltipContent hideLabel nameKey="device" />}
            />
            <Pie
              data={chartData}
              dataKey="users"
              nameKey="device"
              outerRadius="68%"
              stroke="muted"
              strokeWidth={2}
              labelLine={{ stroke: "input" }}
              label={({ name }) =>
                chartConfig[name as keyof typeof chartConfig].label
              }
            />
          </PieChart>
        </ChartContainer>
      </CardContent>
    </Card>
  )
}
```

```swift title="swift/Charts/PieChartLabel.swift"
import Charts
import SwiftUI

private let chartData: [(device: String, users: Double)] = [
  ("phone", 275), ("laptop", 200), ("tablet", 187), ("watch", 173), ("other", 90),
]

private let chartConfig: ChartConfig = [
  "users": .init("Users"),
  "phone": .init("Phone", color: EsuissColor.chart1),
  "laptop": .init("Laptop", color: EsuissColor.chart2),
  "tablet": .init("Tablet", color: EsuissColor.chart3),
  "watch": .init("Watch", color: EsuissColor.chart4),
  "other": .init("Other", color: EsuissColor.chart5),
]

private let total = chartData.reduce(0) { $0 + $1.users }

public struct PieChartLabel: View {
  @State private var selection: Int?

  public init() {}

  public var body: some View {
    Card(.filled, size: .sm) {
      CardHeader("Labeled", description: "Each name sits outside its slice")
      CardContent {
        ChartContainer(config: chartConfig) {
          ChartAnimator { progress in
            Chart {
              ForEach(chartData, id: \.device) { item in
                SectorMark(angle: .value("Users", item.users * progress), outerRadius: .ratio(0.68), angularInset: 1)
                  .foregroundStyle(chartConfig.color(item.device))
              }
              ChartSectorRest(total: total, progress: progress)
            }
            .overlay {
              GeometryReader { geometry in
                let center = CGPoint(x: geometry.size.width / 2, y: geometry.size.height / 2)
                let radius = min(geometry.size.width, geometry.size.height) / 2 * 0.68
                ForEach(chartData.indices, id: \.self) { index in
                  let before = chartData.prefix(index).reduce(0) { $0 + $1.users }
                  let angle = (before + chartData[index].users / 2) / total * 2 * .pi
                  let start = point(center, radius, angle)
                  let end = point(center, radius + 20, angle)
                  Path { path in
                    path.move(to: start)
                    path.addLine(to: end)
                  }
                  .stroke(EsuissColor.input, lineWidth: 1)
                  Text(LocalizedStringKey(chartConfig.label(chartData[index].device)))
                    .scaledFont(TextStyle.xs, weight: .semibold)
                    .foregroundStyle(EsuissColor.foreground)
                    .fixedSize()
                    .frame(width: 0, height: 0, alignment: sin(angle) >= 0 ? .leading : .trailing)
                    .position(x: end.x + (sin(angle) >= 0 ? 2 : -2), y: end.y)
                }
              }
              .opacity(progress < 1 ? 0 : 1)
              .allowsHitTesting(false)
              .accessibilityHidden(true)
            }
            .chartTooltip(
              angle: chartData.map(\.users),
              labels: chartData.map { chartConfig.label($0.device) },
              outerRadius: 0.68,
              selection: $selection,
              accessibilityLabel: "Labeled",
              items: { [ChartTooltipItem(chartData[$0].device, value: chartData[$0].users)] }
            ) { payload in
              ChartTooltipContent(payload, hideLabel: true)
            }
            .padding(5)
          }
        }
        .frame(height: 208)
      }
    }
  }

  private func point(_ center: CGPoint, _ radius: CGFloat, _ angle: Double) -> CGPoint {
    CGPoint(x: center.x + radius * sin(angle), y: center.y - radius * cos(angle))
  }
}
```

```kt title="kotlin/charts/PieChartLabel.kt"
package com.esuiss.ui.charts

import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.esuiss.ui.components.Card
import com.esuiss.ui.components.CardContent
import com.esuiss.ui.components.CardHeader
import com.esuiss.ui.components.CardSize
import com.esuiss.ui.components.CardVariant
import com.esuiss.ui.components.ChartConfig
import com.esuiss.ui.components.ChartConfigItem
import com.esuiss.ui.components.ChartContainer
import com.esuiss.ui.components.ChartTooltipContent
import com.esuiss.ui.components.PieChart
import com.esuiss.ui.theme.EsuissTheme

private class PieLabelDeviceUsers(val device: String, val users: Double)

private val chartData = listOf(
    PieLabelDeviceUsers("phone", 275.0),
    PieLabelDeviceUsers("laptop", 200.0),
    PieLabelDeviceUsers("tablet", 187.0),
    PieLabelDeviceUsers("watch", 173.0),
    PieLabelDeviceUsers("other", 90.0),
)

private val chartConfig = ChartConfig(
    "users" to ChartConfigItem("Users"),
    "phone" to ChartConfigItem("Phone") { chart1 },
    "laptop" to ChartConfigItem("Laptop") { chart2 },
    "tablet" to ChartConfigItem("Tablet") { chart3 },
    "watch" to ChartConfigItem("Watch") { chart4 },
    "other" to ChartConfigItem("Other") { chart5 },
)

@Composable
fun PieChartLabel(modifier: Modifier = Modifier) {
    val colors = EsuissTheme.colors
    Card(modifier, variant = CardVariant.Filled, size = CardSize.Sm) {
        CardHeader("Labeled", description = "Each name sits outside its slice")
        CardContent {
            ChartContainer(
                chartConfig,
                Modifier
                    .fillMaxWidth()
                    .height(208.dp),
            ) {
                PieChart(accessibilityLabel = "Labeled") {
                    ChartTooltip { ChartTooltipContent(hideLabel = true) }
                    Pie(
                        chartData,
                        value = { it.users },
                        nameKey = { it.device },
                        outerRadius = 0.68f,
                        stroke = colors.muted,
                        strokeWidth = 2.dp,
                        label = { index -> chartConfig[chartData[index].device]?.label ?: "" },
                        labelLine = colors.input,
                    )
                }
            }
        }
    }
}
```

**React Native, Jetpack Compose**

A `PieChart` with a smaller radius to leave room for labels. `chartData` holds one record per device with a `users` count. The `label` callback reads each slice name from `chartConfig`, and `labelLine` draws the connector. Pressing a slice shows a tooltip.

**React Native**

Replace `chartData` with your records and keep `dataKey` and `nameKey` in step with your field names. Add one entry per slice to `chartConfig` with its label and color; the component takes no props.

**React Native, SwiftUI, Jetpack Compose**

### Installation

**Command**

**React Native**

```bash title="Terminal"
npx shadcn@latest add @esuiss/pie-chart-label
```

See [Installation](https://suiss.app/ui/docs/installation) for the `components.json` setup. Or use the [suiss/ui CLI](https://suiss.app/ui/docs/cli):

```bash title="Terminal"
npx @esuiss/ui@latest add charts pie-chart-label
```

**SwiftUI**

```bash title="Terminal"
npx shadcn@latest add @esuiss/pie-chart-label
```

See [Installation](https://suiss.app/ui/docs/installation) for the `components.json` setup. Or use the [suiss/ui CLI](https://suiss.app/ui/docs/cli):

```bash title="Terminal"
npx @esuiss/ui@latest add charts pie-chart-label --platform swift
```

**Jetpack Compose**

```bash title="Terminal"
npx shadcn@latest add @esuiss/pie-chart-label
```

See [Installation](https://suiss.app/ui/docs/installation) for the `components.json` setup. Or use the [suiss/ui CLI](https://suiss.app/ui/docs/cli):

```bash title="Terminal"
npx @esuiss/ui@latest add charts pie-chart-label --platform kotlin
```

**React Native**

The CLI also adds what it builds on: [Card](https://suiss.app/ui/docs/components/card), [Chart](https://suiss.app/ui/docs/components/chart).

**React Native, SwiftUI, Jetpack Compose**

**Manual**

**React Native**

**Uniwind**

1. Add the pieces it builds on: [Card](https://suiss.app/ui/docs/components/card), [Chart](https://suiss.app/ui/docs/components/chart).

2. Copy and paste the following code into `components/charts/pie-chart-label.tsx`:

- `uniwind/components/charts/pie-chart-label.tsx`: shown above

3. Update the import paths to match your project setup.

**NativeWind**

1. Add the pieces it builds on: [Card](https://suiss.app/ui/docs/components/card), [Chart](https://suiss.app/ui/docs/components/chart).

2. Copy and paste the following code into `components/charts/pie-chart-label.tsx`:

```tsx title="nativewind/components/charts/pie-chart-label.tsx"
import {
  Card,
  CardContent,
  CardDescription,
  CardHeader,
  CardTitle,
} from "@/components/ui/card"
import {
  type ChartConfig,
  ChartContainer,
  ChartTooltip,
  ChartTooltipContent,
  Pie,
  PieChart,
} from "@/components/ui/chart"

const chartData = [
  { device: "phone", users: 275 },
  { device: "laptop", users: 200 },
  { device: "tablet", users: 187 },
  { device: "watch", users: 173 },
  { device: "other", users: 90 },
]

const chartConfig = {
  users: { label: "Users" },
  phone: { label: "Phone", color: "chart-1" },
  laptop: { label: "Laptop", color: "chart-2" },
  tablet: { label: "Tablet", color: "chart-3" },
  watch: { label: "Watch", color: "chart-4" },
  other: { label: "Other", color: "chart-5" },
} satisfies ChartConfig

export function PieChartLabel() {
  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>Labeled</CardTitle>
        <CardDescription>Each name sits outside its slice</CardDescription>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          accessibilityLabel="Labeled"
          className="h-52 w-full"
        >
          <PieChart>
            <ChartTooltip
              cursor={false}
              content={<ChartTooltipContent hideLabel nameKey="device" />}
            />
            <Pie
              data={chartData}
              dataKey="users"
              nameKey="device"
              outerRadius="68%"
              stroke="muted"
              strokeWidth={2}
              labelLine={{ stroke: "input" }}
              label={({ name }) =>
                chartConfig[name as keyof typeof chartConfig].label
              }
            />
          </PieChart>
        </ChartContainer>
      </CardContent>
    </Card>
  )
}
```

3. Update the import paths to match your project setup.

**StyleSheet**

1. Add the pieces it builds on: [Card](https://suiss.app/ui/docs/components/card), [Chart](https://suiss.app/ui/docs/components/chart).

2. Copy and paste the following code into `components/charts/pie-chart-label.tsx`:

```tsx title="stylesheet/components/charts/pie-chart-label.tsx"
import {
  Card,
  CardContent,
  CardDescription,
  CardHeader,
  CardTitle,
} from "@/components/ui/card"
import {
  type ChartConfig,
  ChartContainer,
  ChartTooltip,
  ChartTooltipContent,
  Pie,
  PieChart,
} from "@/components/ui/chart"

const chartData = [
  { device: "phone", users: 275 },
  { device: "laptop", users: 200 },
  { device: "tablet", users: 187 },
  { device: "watch", users: 173 },
  { device: "other", users: 90 },
]

const chartConfig = {
  users: { label: "Users" },
  phone: { label: "Phone", color: "chart-1" },
  laptop: { label: "Laptop", color: "chart-2" },
  tablet: { label: "Tablet", color: "chart-3" },
  watch: { label: "Watch", color: "chart-4" },
  other: { label: "Other", color: "chart-5" },
} satisfies ChartConfig

export function PieChartLabel() {
  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>Labeled</CardTitle>
        <CardDescription>Each name sits outside its slice</CardDescription>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          accessibilityLabel="Labeled"
          style={{ height: 208 }}
        >
          <PieChart>
            <ChartTooltip
              cursor={false}
              content={<ChartTooltipContent hideLabel nameKey="device" />}
            />
            <Pie
              data={chartData}
              dataKey="users"
              nameKey="device"
              outerRadius="68%"
              stroke="muted"
              strokeWidth={2}
              labelLine={{ stroke: "input" }}
              label={({ name }) =>
                chartConfig[name as keyof typeof chartConfig].label
              }
            />
          </PieChart>
        </ChartContainer>
      </CardContent>
    </Card>
  )
}
```

3. Update the import paths to match your project setup.

**SwiftUI**

1. Target iOS 17 or later.

2. Copy the theme files every view uses:

- `swift/Theme/Theme.swift`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/swiftui/Sources/EsuissUI/Theme/Theme.swift)

- `swift/Theme/Tokens.swift`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/swiftui/Sources/EsuissUI/Theme/Tokens.swift)

3. Copy the source and every file it uses:

- `swift/Charts/PieChartLabel.swift`: shown above

- `swift/Components/Card.swift`: see [Card](https://suiss.app/ui/docs/components/card.md)

- `swift/Components/Chart.swift`: see [Chart](https://suiss.app/ui/docs/components/chart.md)

- `swift/Components/Haptics.swift`: see [Haptics](https://suiss.app/ui/docs/components/haptics.md)

- `swift/Components/Item.swift`: see [Item](https://suiss.app/ui/docs/components/item.md)

- `swift/Components/Separator.swift`: see [Separator](https://suiss.app/ui/docs/components/separator.md)

4. Add the files to your app target.

**Jetpack Compose**

1. Apply the Compose compiler plugin, enable Compose, set `compileSdk` to 37 or higher and `minSdk` to 24 or higher, and add the dependencies:

```kotlin title="build.gradle.kts"
plugins {
    id("org.jetbrains.kotlin.plugin.compose")
}

android {
    compileSdk = 37
    defaultConfig { minSdk = 24 }
    buildFeatures { compose = true }
}

dependencies {
    implementation(platform("androidx.compose:compose-bom:2026.09.00"))
    implementation("androidx.compose.foundation:foundation")
    implementation("androidx.compose.ui:ui")
}
```

2. Copy the theme files every view uses:

- `kotlin/theme/Theme.kt`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/kotlin/ui/src/main/kotlin/com/esuiss/ui/theme/Theme.kt)

- `kotlin/theme/Tokens.kt`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/kotlin/ui/src/main/kotlin/com/esuiss/ui/theme/Tokens.kt)

3. Copy the source and every file it uses:

- `kotlin/charts/PieChartLabel.kt`: shown above

- `kotlin/components/Card.kt`: see [Card](https://suiss.app/ui/docs/components/card.md)

- `kotlin/components/Chart.kt`: see [Chart](https://suiss.app/ui/docs/components/chart.md)

- `kotlin/components/Content.kt`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/kotlin/ui/src/main/kotlin/com/esuiss/ui/components/Content.kt)

- `kotlin/components/FormSupport.kt`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/kotlin/ui/src/main/kotlin/com/esuiss/ui/components/FormSupport.kt)

- `kotlin/components/Haptics.kt`: see [Haptics](https://suiss.app/ui/docs/components/haptics.md)

- `kotlin/components/Icon.kt`: see [Icon](https://suiss.app/ui/docs/components/icon.md)

4. Update the `com.esuiss.ui` package names to match your project.

**React Native, SwiftUI, Jetpack Compose**

### Usage

**React Native**

```tsx
import { PieChartLabel } from "@/components/charts/pie-chart-label"
```

```tsx
<PieChartLabel />
```

**SwiftUI**

```swift
import SwiftUI

struct PieLabelExample: View {
  var body: some View {
    PieChartLabel()
  }
}
```

**Jetpack Compose**

```kotlin
import androidx.compose.runtime.Composable
import com.esuiss.ui.charts.PieChartLabel

@Composable
fun PieLabelExample() {
    PieChartLabel()
}
```



## Pie Chart Legend

A donut with a legend beneath it that lists every category and its color.

Source: https://suiss.app/ui/docs/charts/pie-chart#legend

**React**

**Example**

```tsx title="components/charts/pie-chart-legend.tsx"
"use client"

import { Pie, PieChart } from "recharts"

import {
  Card,
  CardContent,
  CardDescription,
  CardHeader,
  CardTitle,
} from "@/components/ui/card"
import {
  type ChartConfig,
  ChartContainer,
  ChartLegend,
  ChartLegendContent,
  ChartTooltip,
  ChartTooltipContent,
} from "@/components/ui/chart"

const chartData = [
  { device: "phone", users: 275, fill: "var(--color-phone)" },
  { device: "laptop", users: 200, fill: "var(--color-laptop)" },
  { device: "tablet", users: 187, fill: "var(--color-tablet)" },
  { device: "watch", users: 173, fill: "var(--color-watch)" },
  { device: "other", users: 90, fill: "var(--color-other)" },
]

const chartConfig = {
  users: { label: "Users" },
  phone: { label: "Phone", color: "var(--chart-1)" },
  laptop: { label: "Laptop", color: "var(--chart-2)" },
  tablet: { label: "Tablet", color: "var(--chart-3)" },
  watch: { label: "Watch", color: "var(--chart-4)" },
  other: { label: "Other", color: "var(--chart-5)" },
} satisfies ChartConfig

export function PieChartLegend() {
  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>With a legend</CardTitle>
        <CardDescription>What each color means</CardDescription>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          className="aspect-auto h-60 w-full"
        >
          <PieChart accessibilityLayer>
            <ChartTooltip
              cursor={false}
              content={<ChartTooltipContent hideLabel nameKey="device" />}
            />
            <ChartLegend
              verticalAlign="bottom"
              content={<ChartLegendContent nameKey="device" />}
            />
            <Pie
              data={chartData}
              dataKey="users"
              nameKey="device"
              cy="45%"
              innerRadius="50%"
              outerRadius="78%"
              strokeWidth={0}
              paddingAngle={1}
            />
          </PieChart>
        </ChartContainer>
      </CardContent>
    </Card>
  )
}
```

A donut with a legend underneath listing every category and its color. Pick it when a chart has enough slices that labels around the ring would get crowded.

Replace `chartData` and add a label and color for each category to `chartConfig`; the legend reads both from there. Keep `nameKey` on the legend content set to your category field so the names resolve.

### Installation

**Command**

```bash title="Terminal"
npx shadcn@latest add @esuiss/pie-chart-legend
```

Works in any project with a `components.json`. See [Installation](https://suiss.app/ui/docs/installation#add-components) for the one-line registry setup. Or use the [suiss/ui CLI](https://suiss.app/ui/docs/cli):

```bash title="Terminal"
npx @esuiss/ui@latest add charts pie-chart-legend
```

**Manual**

1. Install the following dependencies:

```bash title="Terminal"
npm install recharts
```

2. Add the pieces it builds on: [Card](https://suiss.app/ui/docs/components/card), [Chart](https://suiss.app/ui/docs/components/chart).

3. Copy and paste the following code into your project.

```tsx title="components/charts/pie-chart-legend.tsx"
"use client"

import { Pie, PieChart } from "recharts"

import {
  Card,
  CardContent,
  CardDescription,
  CardHeader,
  CardTitle,
} from "@/components/ui/card"
import {
  type ChartConfig,
  ChartContainer,
  ChartLegend,
  ChartLegendContent,
  ChartTooltip,
  ChartTooltipContent,
} from "@/components/ui/chart"

const chartData = [
  { device: "phone", users: 275, fill: "var(--color-phone)" },
  { device: "laptop", users: 200, fill: "var(--color-laptop)" },
  { device: "tablet", users: 187, fill: "var(--color-tablet)" },
  { device: "watch", users: 173, fill: "var(--color-watch)" },
  { device: "other", users: 90, fill: "var(--color-other)" },
]

const chartConfig = {
  users: { label: "Users" },
  phone: { label: "Phone", color: "var(--chart-1)" },
  laptop: { label: "Laptop", color: "var(--chart-2)" },
  tablet: { label: "Tablet", color: "var(--chart-3)" },
  watch: { label: "Watch", color: "var(--chart-4)" },
  other: { label: "Other", color: "var(--chart-5)" },
} satisfies ChartConfig

export function PieChartLegend() {
  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>With a legend</CardTitle>
        <CardDescription>What each color means</CardDescription>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          className="aspect-auto h-60 w-full"
        >
          <PieChart accessibilityLayer>
            <ChartTooltip
              cursor={false}
              content={<ChartTooltipContent hideLabel nameKey="device" />}
            />
            <ChartLegend
              verticalAlign="bottom"
              content={<ChartLegendContent nameKey="device" />}
            />
            <Pie
              data={chartData}
              dataKey="users"
              nameKey="device"
              cy="45%"
              innerRadius="50%"
              outerRadius="78%"
              strokeWidth={0}
              paddingAngle={1}
            />
          </PieChart>
        </ChartContainer>
      </CardContent>
    </Card>
  )
}
```

4. Update the import paths to match your project setup.

### Usage

```tsx
import { PieChartLegend } from "@/components/charts/pie-chart-legend"
```

```tsx
<PieChartLegend />
```

**React Native, SwiftUI, Jetpack Compose**

```tsx title="uniwind/components/charts/pie-chart-legend.tsx"
import {
  Card,
  CardContent,
  CardDescription,
  CardHeader,
  CardTitle,
} from "@/components/ui/card"
import {
  type ChartConfig,
  ChartContainer,
  ChartLegend,
  ChartLegendContent,
  ChartTooltip,
  ChartTooltipContent,
  Pie,
  PieChart,
} from "@/components/ui/chart"

const chartData = [
  { device: "phone", users: 275 },
  { device: "laptop", users: 200 },
  { device: "tablet", users: 187 },
  { device: "watch", users: 173 },
  { device: "other", users: 90 },
]

const chartConfig = {
  users: { label: "Users" },
  phone: { label: "Phone", color: "chart-1" },
  laptop: { label: "Laptop", color: "chart-2" },
  tablet: { label: "Tablet", color: "chart-3" },
  watch: { label: "Watch", color: "chart-4" },
  other: { label: "Other", color: "chart-5" },
} satisfies ChartConfig

export function PieChartLegend() {
  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>With a legend</CardTitle>
        <CardDescription>What each color means</CardDescription>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          accessibilityLabel="With a legend"
          className="h-60 w-full"
        >
          <PieChart>
            <ChartTooltip
              cursor={false}
              content={<ChartTooltipContent hideLabel nameKey="device" />}
            />
            <ChartLegend content={<ChartLegendContent nameKey="device" />} />
            <Pie
              data={chartData}
              dataKey="users"
              nameKey="device"
              cy="45%"
              innerRadius="50%"
              outerRadius="78%"
              strokeWidth={0}
              paddingAngle={1}
            />
          </PieChart>
        </ChartContainer>
      </CardContent>
    </Card>
  )
}
```

```swift title="swift/Charts/PieChartLegend.swift"
import Charts
import SwiftUI

private let chartData: [(device: String, users: Double)] = [
  ("phone", 275), ("laptop", 200), ("tablet", 187), ("watch", 173), ("other", 90),
]

private let chartConfig: ChartConfig = [
  "users": .init("Users"),
  "phone": .init("Phone", color: EsuissColor.chart1),
  "laptop": .init("Laptop", color: EsuissColor.chart2),
  "tablet": .init("Tablet", color: EsuissColor.chart3),
  "watch": .init("Watch", color: EsuissColor.chart4),
  "other": .init("Other", color: EsuissColor.chart5),
]

public struct PieChartLegend: View {
  @State private var selection: Int?

  public init() {}

  public var body: some View {
    Card(.filled, size: .sm) {
      CardHeader("With a legend", description: "What each color means")
      CardContent {
        ChartContainer(config: chartConfig) {
          ChartAnimator { progress in
            Chart {
              ForEach(chartData, id: \.device) { item in
                SectorMark(angle: .value("Users", item.users * progress), innerRadius: .ratio(0.5), outerRadius: .ratio(0.78), angularInset: 0.75)
                  .foregroundStyle(chartConfig.color(item.device))
              }
              ChartSectorRest(total: chartData.reduce(0) { $0 + $1.users }, progress: progress)
            }
            .chartTooltip(
              angle: chartData.map(\.users),
              labels: chartData.map { chartConfig.label($0.device) },
              innerRadius: 0.5,
              outerRadius: 0.78,
              selection: $selection,
              accessibilityLabel: "With a legend",
              items: { [ChartTooltipItem(chartData[$0].device, value: chartData[$0].users)] }
            ) { payload in
              ChartTooltipContent(payload, hideLabel: true)
            }
            .padding(5)
          }
          ChartLegendContent(keys: chartData.map(\.device))
        }
        .frame(height: 240)
      }
    }
  }
}
```

```kt title="kotlin/charts/PieChartLegend.kt"
package com.esuiss.ui.charts

import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.esuiss.ui.components.Card
import com.esuiss.ui.components.CardContent
import com.esuiss.ui.components.CardHeader
import com.esuiss.ui.components.CardSize
import com.esuiss.ui.components.CardVariant
import com.esuiss.ui.components.ChartConfig
import com.esuiss.ui.components.ChartConfigItem
import com.esuiss.ui.components.ChartContainer
import com.esuiss.ui.components.ChartTooltipContent
import com.esuiss.ui.components.PieChart

private class PieLegendDeviceUsers(val device: String, val users: Double)

private val chartData = listOf(
    PieLegendDeviceUsers("phone", 275.0),
    PieLegendDeviceUsers("laptop", 200.0),
    PieLegendDeviceUsers("tablet", 187.0),
    PieLegendDeviceUsers("watch", 173.0),
    PieLegendDeviceUsers("other", 90.0),
)

private val chartConfig = ChartConfig(
    "users" to ChartConfigItem("Users"),
    "phone" to ChartConfigItem("Phone") { chart1 },
    "laptop" to ChartConfigItem("Laptop") { chart2 },
    "tablet" to ChartConfigItem("Tablet") { chart3 },
    "watch" to ChartConfigItem("Watch") { chart4 },
    "other" to ChartConfigItem("Other") { chart5 },
)

@Composable
fun PieChartLegend(modifier: Modifier = Modifier) {
    Card(modifier, variant = CardVariant.Filled, size = CardSize.Sm) {
        CardHeader("With a legend", description = "What each color means")
        CardContent {
            ChartContainer(
                chartConfig,
                Modifier
                    .fillMaxWidth()
                    .height(240.dp),
            ) {
                PieChart(accessibilityLabel = "With a legend") {
                    ChartTooltip { ChartTooltipContent(hideLabel = true) }
                    ChartLegend()
                    Pie(
                        chartData,
                        value = { it.users },
                        nameKey = { it.device },
                        innerRadius = 0.5f,
                        outerRadius = 0.78f,
                        strokeWidth = 0.dp,
                        paddingAngle = 1f,
                    )
                }
            }
        }
    }
}
```

**React Native, Jetpack Compose**

A `PieChart` donut with a `ChartLegend` that lists every slice from `chartConfig`. `chartData` holds one record per device with a `users` count. Pressing a slice shows a tooltip.

**React Native**

Replace `chartData` with your records and keep `dataKey` and `nameKey` in step with your field names. Add one entry per slice to `chartConfig` with its label and color; the component takes no props.

**React Native, SwiftUI, Jetpack Compose**

### Installation

**Command**

**React Native**

```bash title="Terminal"
npx shadcn@latest add @esuiss/pie-chart-legend
```

See [Installation](https://suiss.app/ui/docs/installation) for the `components.json` setup. Or use the [suiss/ui CLI](https://suiss.app/ui/docs/cli):

```bash title="Terminal"
npx @esuiss/ui@latest add charts pie-chart-legend
```

**SwiftUI**

```bash title="Terminal"
npx shadcn@latest add @esuiss/pie-chart-legend
```

See [Installation](https://suiss.app/ui/docs/installation) for the `components.json` setup. Or use the [suiss/ui CLI](https://suiss.app/ui/docs/cli):

```bash title="Terminal"
npx @esuiss/ui@latest add charts pie-chart-legend --platform swift
```

**Jetpack Compose**

```bash title="Terminal"
npx shadcn@latest add @esuiss/pie-chart-legend
```

See [Installation](https://suiss.app/ui/docs/installation) for the `components.json` setup. Or use the [suiss/ui CLI](https://suiss.app/ui/docs/cli):

```bash title="Terminal"
npx @esuiss/ui@latest add charts pie-chart-legend --platform kotlin
```

**React Native**

The CLI also adds what it builds on: [Card](https://suiss.app/ui/docs/components/card), [Chart](https://suiss.app/ui/docs/components/chart).

**React Native, SwiftUI, Jetpack Compose**

**Manual**

**React Native**

**Uniwind**

1. Add the pieces it builds on: [Card](https://suiss.app/ui/docs/components/card), [Chart](https://suiss.app/ui/docs/components/chart).

2. Copy and paste the following code into `components/charts/pie-chart-legend.tsx`:

- `uniwind/components/charts/pie-chart-legend.tsx`: shown above

3. Update the import paths to match your project setup.

**NativeWind**

1. Add the pieces it builds on: [Card](https://suiss.app/ui/docs/components/card), [Chart](https://suiss.app/ui/docs/components/chart).

2. Copy and paste the following code into `components/charts/pie-chart-legend.tsx`:

```tsx title="nativewind/components/charts/pie-chart-legend.tsx"
import {
  Card,
  CardContent,
  CardDescription,
  CardHeader,
  CardTitle,
} from "@/components/ui/card"
import {
  type ChartConfig,
  ChartContainer,
  ChartLegend,
  ChartLegendContent,
  ChartTooltip,
  ChartTooltipContent,
  Pie,
  PieChart,
} from "@/components/ui/chart"

const chartData = [
  { device: "phone", users: 275 },
  { device: "laptop", users: 200 },
  { device: "tablet", users: 187 },
  { device: "watch", users: 173 },
  { device: "other", users: 90 },
]

const chartConfig = {
  users: { label: "Users" },
  phone: { label: "Phone", color: "chart-1" },
  laptop: { label: "Laptop", color: "chart-2" },
  tablet: { label: "Tablet", color: "chart-3" },
  watch: { label: "Watch", color: "chart-4" },
  other: { label: "Other", color: "chart-5" },
} satisfies ChartConfig

export function PieChartLegend() {
  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>With a legend</CardTitle>
        <CardDescription>What each color means</CardDescription>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          accessibilityLabel="With a legend"
          className="h-60 w-full"
        >
          <PieChart>
            <ChartTooltip
              cursor={false}
              content={<ChartTooltipContent hideLabel nameKey="device" />}
            />
            <ChartLegend content={<ChartLegendContent nameKey="device" />} />
            <Pie
              data={chartData}
              dataKey="users"
              nameKey="device"
              cy="45%"
              innerRadius="50%"
              outerRadius="78%"
              strokeWidth={0}
              paddingAngle={1}
            />
          </PieChart>
        </ChartContainer>
      </CardContent>
    </Card>
  )
}
```

3. Update the import paths to match your project setup.

**StyleSheet**

1. Add the pieces it builds on: [Card](https://suiss.app/ui/docs/components/card), [Chart](https://suiss.app/ui/docs/components/chart).

2. Copy and paste the following code into `components/charts/pie-chart-legend.tsx`:

```tsx title="stylesheet/components/charts/pie-chart-legend.tsx"
import {
  Card,
  CardContent,
  CardDescription,
  CardHeader,
  CardTitle,
} from "@/components/ui/card"
import {
  type ChartConfig,
  ChartContainer,
  ChartLegend,
  ChartLegendContent,
  ChartTooltip,
  ChartTooltipContent,
  Pie,
  PieChart,
} from "@/components/ui/chart"

const chartData = [
  { device: "phone", users: 275 },
  { device: "laptop", users: 200 },
  { device: "tablet", users: 187 },
  { device: "watch", users: 173 },
  { device: "other", users: 90 },
]

const chartConfig = {
  users: { label: "Users" },
  phone: { label: "Phone", color: "chart-1" },
  laptop: { label: "Laptop", color: "chart-2" },
  tablet: { label: "Tablet", color: "chart-3" },
  watch: { label: "Watch", color: "chart-4" },
  other: { label: "Other", color: "chart-5" },
} satisfies ChartConfig

export function PieChartLegend() {
  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>With a legend</CardTitle>
        <CardDescription>What each color means</CardDescription>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          accessibilityLabel="With a legend"
          style={{ height: 240 }}
        >
          <PieChart>
            <ChartTooltip
              cursor={false}
              content={<ChartTooltipContent hideLabel nameKey="device" />}
            />
            <ChartLegend content={<ChartLegendContent nameKey="device" />} />
            <Pie
              data={chartData}
              dataKey="users"
              nameKey="device"
              cy="45%"
              innerRadius="50%"
              outerRadius="78%"
              strokeWidth={0}
              paddingAngle={1}
            />
          </PieChart>
        </ChartContainer>
      </CardContent>
    </Card>
  )
}
```

3. Update the import paths to match your project setup.

**SwiftUI**

1. Target iOS 17 or later.

2. Copy the theme files every view uses:

- `swift/Theme/Theme.swift`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/swiftui/Sources/EsuissUI/Theme/Theme.swift)

- `swift/Theme/Tokens.swift`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/swiftui/Sources/EsuissUI/Theme/Tokens.swift)

3. Copy the source and every file it uses:

- `swift/Charts/PieChartLegend.swift`: shown above

- `swift/Components/Card.swift`: see [Card](https://suiss.app/ui/docs/components/card.md)

- `swift/Components/Chart.swift`: see [Chart](https://suiss.app/ui/docs/components/chart.md)

- `swift/Components/Haptics.swift`: see [Haptics](https://suiss.app/ui/docs/components/haptics.md)

- `swift/Components/Item.swift`: see [Item](https://suiss.app/ui/docs/components/item.md)

- `swift/Components/Separator.swift`: see [Separator](https://suiss.app/ui/docs/components/separator.md)

4. Add the files to your app target.

**Jetpack Compose**

1. Apply the Compose compiler plugin, enable Compose, set `compileSdk` to 37 or higher and `minSdk` to 24 or higher, and add the dependencies:

```kotlin title="build.gradle.kts"
plugins {
    id("org.jetbrains.kotlin.plugin.compose")
}

android {
    compileSdk = 37
    defaultConfig { minSdk = 24 }
    buildFeatures { compose = true }
}

dependencies {
    implementation(platform("androidx.compose:compose-bom:2026.09.00"))
    implementation("androidx.compose.foundation:foundation")
    implementation("androidx.compose.ui:ui")
}
```

2. Copy the theme files every view uses:

- `kotlin/theme/Theme.kt`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/kotlin/ui/src/main/kotlin/com/esuiss/ui/theme/Theme.kt)

- `kotlin/theme/Tokens.kt`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/kotlin/ui/src/main/kotlin/com/esuiss/ui/theme/Tokens.kt)

3. Copy the source and every file it uses:

- `kotlin/charts/PieChartLegend.kt`: shown above

- `kotlin/components/Card.kt`: see [Card](https://suiss.app/ui/docs/components/card.md)

- `kotlin/components/Chart.kt`: see [Chart](https://suiss.app/ui/docs/components/chart.md)

- `kotlin/components/Content.kt`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/kotlin/ui/src/main/kotlin/com/esuiss/ui/components/Content.kt)

- `kotlin/components/FormSupport.kt`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/kotlin/ui/src/main/kotlin/com/esuiss/ui/components/FormSupport.kt)

- `kotlin/components/Haptics.kt`: see [Haptics](https://suiss.app/ui/docs/components/haptics.md)

- `kotlin/components/Icon.kt`: see [Icon](https://suiss.app/ui/docs/components/icon.md)

4. Update the `com.esuiss.ui` package names to match your project.

**React Native, SwiftUI, Jetpack Compose**

### Usage

**React Native**

```tsx
import { PieChartLegend } from "@/components/charts/pie-chart-legend"
```

```tsx
<PieChartLegend />
```

**SwiftUI**

```swift
import SwiftUI

struct PieLegendExample: View {
  var body: some View {
    PieChartLegend()
  }
}
```

**Jetpack Compose**

```kotlin
import androidx.compose.runtime.Composable
import com.esuiss.ui.charts.PieChartLegend

@Composable
fun PieLegendExample() {
    PieChartLegend()
}
```



## Pie Chart Nested

Two concentric pies: an inner ring of grouped totals surrounded by an outer ring of individual categories.

Source: https://suiss.app/ui/docs/charts/pie-chart#nested

**React**

**Example**

```tsx title="components/charts/pie-chart-nested.tsx"
"use client"

import { Pie, PieChart } from "recharts"

import {
  Card,
  CardContent,
  CardDescription,
  CardHeader,
  CardTitle,
} from "@/components/ui/card"
import {
  type ChartConfig,
  ChartContainer,
  ChartTooltip,
  ChartTooltipContent,
} from "@/components/ui/chart"

const chartData = [
  { device: "phone", users: 275, fill: "var(--color-phone)" },
  { device: "laptop", users: 200, fill: "var(--color-laptop)" },
  { device: "tablet", users: 187, fill: "var(--color-tablet)" },
  { device: "watch", users: 173, fill: "var(--color-watch)" },
  { device: "other", users: 90, fill: "var(--color-other)" },
]

const chartConfig = {
  users: { label: "Users" },
  phone: { label: "Phone", color: "var(--chart-1)" },
  laptop: { label: "Laptop", color: "var(--chart-2)" },
  tablet: { label: "Tablet", color: "var(--chart-3)" },
  watch: { label: "Watch", color: "var(--chart-4)" },
  other: { label: "Other", color: "var(--chart-5)" },
  personal: { label: "Phones and laptops", color: "var(--chart-1)" },
  companion: { label: "Tablets, watches and other", color: "var(--chart-4)" },
} satisfies ChartConfig

const groups = [
  { device: "personal", users: 475, fill: "var(--color-personal)" },
  { device: "companion", users: 450, fill: "var(--color-companion)" },
]

export function PieChartNested() {
  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>Nested</CardTitle>
        <CardDescription>Groups inside, details outside</CardDescription>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          className="aspect-auto h-52 w-full"
        >
          <PieChart accessibilityLayer>
            <ChartTooltip
              cursor={false}
              content={<ChartTooltipContent hideLabel nameKey="device" />}
            />
            <Pie
              data={groups}
              dataKey="users"
              nameKey="device"
              outerRadius="52%"
              stroke="var(--muted)"
              strokeWidth={2}
              fillOpacity={0.55}
            />
            <Pie
              data={chartData}
              dataKey="users"
              nameKey="device"
              innerRadius="60%"
              outerRadius="86%"
              stroke="var(--muted)"
              strokeWidth={2}
            />
          </PieChart>
        </ChartContainer>
      </CardContent>
    </Card>
  )
}
```

Two concentric rings: a lighter inner pie of group totals surrounded by an outer ring of individual categories. Use it for two-level breakdowns, such as product lines and the products within them.

Put the detailed records in `chartData` and the group totals in `groups`, with each group total equal to the sum of its categories. Order the outer categories so each group's members sit next to their inner slice. The demo groups reuse the Phone and Watch keys, so their tooltips read Phone and Watch; give each group its own key and label in `chartConfig`.

### Installation

**Command**

```bash title="Terminal"
npx shadcn@latest add @esuiss/pie-chart-nested
```

Works in any project with a `components.json`. See [Installation](https://suiss.app/ui/docs/installation#add-components) for the one-line registry setup. Or use the [suiss/ui CLI](https://suiss.app/ui/docs/cli):

```bash title="Terminal"
npx @esuiss/ui@latest add charts pie-chart-nested
```

**Manual**

1. Install the following dependencies:

```bash title="Terminal"
npm install recharts
```

2. Add the pieces it builds on: [Card](https://suiss.app/ui/docs/components/card), [Chart](https://suiss.app/ui/docs/components/chart).

3. Copy and paste the following code into your project.

```tsx title="components/charts/pie-chart-nested.tsx"
"use client"

import { Pie, PieChart } from "recharts"

import {
  Card,
  CardContent,
  CardDescription,
  CardHeader,
  CardTitle,
} from "@/components/ui/card"
import {
  type ChartConfig,
  ChartContainer,
  ChartTooltip,
  ChartTooltipContent,
} from "@/components/ui/chart"

const chartData = [
  { device: "phone", users: 275, fill: "var(--color-phone)" },
  { device: "laptop", users: 200, fill: "var(--color-laptop)" },
  { device: "tablet", users: 187, fill: "var(--color-tablet)" },
  { device: "watch", users: 173, fill: "var(--color-watch)" },
  { device: "other", users: 90, fill: "var(--color-other)" },
]

const chartConfig = {
  users: { label: "Users" },
  phone: { label: "Phone", color: "var(--chart-1)" },
  laptop: { label: "Laptop", color: "var(--chart-2)" },
  tablet: { label: "Tablet", color: "var(--chart-3)" },
  watch: { label: "Watch", color: "var(--chart-4)" },
  other: { label: "Other", color: "var(--chart-5)" },
  personal: { label: "Phones and laptops", color: "var(--chart-1)" },
  companion: { label: "Tablets, watches and other", color: "var(--chart-4)" },
} satisfies ChartConfig

const groups = [
  { device: "personal", users: 475, fill: "var(--color-personal)" },
  { device: "companion", users: 450, fill: "var(--color-companion)" },
]

export function PieChartNested() {
  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>Nested</CardTitle>
        <CardDescription>Groups inside, details outside</CardDescription>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          className="aspect-auto h-52 w-full"
        >
          <PieChart accessibilityLayer>
            <ChartTooltip
              cursor={false}
              content={<ChartTooltipContent hideLabel nameKey="device" />}
            />
            <Pie
              data={groups}
              dataKey="users"
              nameKey="device"
              outerRadius="52%"
              stroke="var(--muted)"
              strokeWidth={2}
              fillOpacity={0.55}
            />
            <Pie
              data={chartData}
              dataKey="users"
              nameKey="device"
              innerRadius="60%"
              outerRadius="86%"
              stroke="var(--muted)"
              strokeWidth={2}
            />
          </PieChart>
        </ChartContainer>
      </CardContent>
    </Card>
  )
}
```

4. Update the import paths to match your project setup.

### Usage

```tsx
import { PieChartNested } from "@/components/charts/pie-chart-nested"
```

```tsx
<PieChartNested />
```

**React Native, SwiftUI, Jetpack Compose**

```tsx title="uniwind/components/charts/pie-chart-nested.tsx"
import {
  Card,
  CardContent,
  CardDescription,
  CardHeader,
  CardTitle,
} from "@/components/ui/card"
import {
  type ChartConfig,
  ChartContainer,
  ChartTooltip,
  ChartTooltipContent,
  Pie,
  PieChart,
} from "@/components/ui/chart"

const chartData = [
  { device: "phone", users: 275 },
  { device: "laptop", users: 200 },
  { device: "tablet", users: 187 },
  { device: "watch", users: 173 },
  { device: "other", users: 90 },
]

const chartConfig = {
  users: { label: "Users" },
  phone: { label: "Phone", color: "chart-1" },
  laptop: { label: "Laptop", color: "chart-2" },
  tablet: { label: "Tablet", color: "chart-3" },
  watch: { label: "Watch", color: "chart-4" },
  other: { label: "Other", color: "chart-5" },
} satisfies ChartConfig

const groups = [
  { device: "phone", users: 475 },
  { device: "watch", users: 450 },
]

export function PieChartNested() {
  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>Nested</CardTitle>
        <CardDescription>Groups inside, details outside</CardDescription>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          accessibilityLabel="Nested"
          className="h-52 w-full"
        >
          <PieChart>
            <ChartTooltip
              cursor={false}
              content={<ChartTooltipContent hideLabel nameKey="device" />}
            />
            <Pie
              data={groups}
              dataKey="users"
              nameKey="device"
              outerRadius="52%"
              stroke="muted"
              strokeWidth={2}
              fillOpacity={0.55}
            />
            <Pie
              data={chartData}
              dataKey="users"
              nameKey="device"
              innerRadius="60%"
              outerRadius="86%"
              stroke="muted"
              strokeWidth={2}
            />
          </PieChart>
        </ChartContainer>
      </CardContent>
    </Card>
  )
}
```

```swift title="swift/Charts/PieChartNested.swift"
import Charts
import SwiftUI

private let chartData: [(device: String, users: Double)] = [
  ("phone", 275), ("laptop", 200), ("tablet", 187), ("watch", 173), ("other", 90),
]

private let chartConfig: ChartConfig = [
  "users": .init("Users"),
  "phone": .init("Phone", color: EsuissColor.chart1),
  "laptop": .init("Laptop", color: EsuissColor.chart2),
  "tablet": .init("Tablet", color: EsuissColor.chart3),
  "watch": .init("Watch", color: EsuissColor.chart4),
  "other": .init("Other", color: EsuissColor.chart5),
]

private let groups: [(device: String, users: Double)] = [("phone", 475), ("watch", 450)]

public struct PieChartNested: View {
  @State private var selection: Int?

  public init() {}

  public var body: some View {
    Card(.filled, size: .sm) {
      CardHeader("Nested", description: "Groups inside, details outside")
      CardContent {
        ChartContainer(config: chartConfig) {
          ChartAnimator { progress in
            ZStack {
              Chart {
                ForEach(groups, id: \.device) { item in
                  SectorMark(angle: .value("Users", item.users * progress), outerRadius: .ratio(0.52), angularInset: 1)
                    .foregroundStyle(chartConfig.color(item.device).opacity(0.55))
                }
                ChartSectorRest(total: groups.reduce(0) { $0 + $1.users }, progress: progress)
              }
              .accessibilityHidden(true)
              Chart {
                ForEach(chartData, id: \.device) { item in
                  SectorMark(angle: .value("Users", item.users * progress), innerRadius: .ratio(0.6), outerRadius: .ratio(0.86), angularInset: 1)
                    .foregroundStyle(chartConfig.color(item.device))
                }
                ChartSectorRest(total: chartData.reduce(0) { $0 + $1.users }, progress: progress)
              }
              .chartTooltip(
                angle: chartData.map(\.users),
                labels: chartData.map { chartConfig.label($0.device) },
                outerRadius: 0.86,
                selection: $selection,
                accessibilityLabel: "Nested",
                items: { [ChartTooltipItem(chartData[$0].device, value: chartData[$0].users)] }
              ) { payload in
                ChartTooltipContent(payload, hideLabel: true)
              }
            }
            .padding(5)
          }
        }
        .frame(height: 208)
      }
    }
  }
}
```

```kt title="kotlin/charts/PieChartNested.kt"
package com.esuiss.ui.charts

import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.esuiss.ui.components.Card
import com.esuiss.ui.components.CardContent
import com.esuiss.ui.components.CardHeader
import com.esuiss.ui.components.CardSize
import com.esuiss.ui.components.CardVariant
import com.esuiss.ui.components.ChartConfig
import com.esuiss.ui.components.ChartConfigItem
import com.esuiss.ui.components.ChartContainer
import com.esuiss.ui.components.ChartTooltipContent
import com.esuiss.ui.components.PieChart
import com.esuiss.ui.theme.EsuissTheme

private class PieNestedDeviceUsers(val device: String, val users: Double)

private val chartData = listOf(
    PieNestedDeviceUsers("phone", 275.0),
    PieNestedDeviceUsers("laptop", 200.0),
    PieNestedDeviceUsers("tablet", 187.0),
    PieNestedDeviceUsers("watch", 173.0),
    PieNestedDeviceUsers("other", 90.0),
)

private val groups = listOf(
    PieNestedDeviceUsers("phone", 475.0),
    PieNestedDeviceUsers("watch", 450.0),
)

private val chartConfig = ChartConfig(
    "users" to ChartConfigItem("Users"),
    "phone" to ChartConfigItem("Phone") { chart1 },
    "laptop" to ChartConfigItem("Laptop") { chart2 },
    "tablet" to ChartConfigItem("Tablet") { chart3 },
    "watch" to ChartConfigItem("Watch") { chart4 },
    "other" to ChartConfigItem("Other") { chart5 },
)

@Composable
fun PieChartNested(modifier: Modifier = Modifier) {
    val colors = EsuissTheme.colors
    Card(modifier, variant = CardVariant.Filled, size = CardSize.Sm) {
        CardHeader("Nested", description = "Groups inside, details outside")
        CardContent {
            ChartContainer(
                chartConfig,
                Modifier
                    .fillMaxWidth()
                    .height(208.dp),
            ) {
                PieChart(accessibilityLabel = "Nested") {
                    ChartTooltip { ChartTooltipContent(hideLabel = true) }
                    Pie(
                        groups,
                        value = { it.users },
                        nameKey = { it.device },
                        outerRadius = 0.52f,
                        stroke = colors.muted,
                        strokeWidth = 2.dp,
                        fillOpacity = 0.55f,
                    )
                    Pie(
                        chartData,
                        value = { it.users },
                        nameKey = { it.device },
                        innerRadius = 0.6f,
                        outerRadius = 0.86f,
                        stroke = colors.muted,
                        strokeWidth = 2.dp,
                    )
                }
            }
        }
    }
}
```

**React Native, Jetpack Compose**

A `PieChart` with two `Pie` layers. The inner pie reads a `groups` array and is drawn at reduced opacity; the outer ring reads `chartData`, one record per device. Pressing a slice in either ring shows a tooltip.

**React Native**

Replace `groups` and `chartData` with your summary and detail records, and add each name to `chartConfig` with its label and color. The component takes no props.

**React Native, SwiftUI, Jetpack Compose**

### Installation

**Command**

**React Native**

```bash title="Terminal"
npx shadcn@latest add @esuiss/pie-chart-nested
```

See [Installation](https://suiss.app/ui/docs/installation) for the `components.json` setup. Or use the [suiss/ui CLI](https://suiss.app/ui/docs/cli):

```bash title="Terminal"
npx @esuiss/ui@latest add charts pie-chart-nested
```

**SwiftUI**

```bash title="Terminal"
npx shadcn@latest add @esuiss/pie-chart-nested
```

See [Installation](https://suiss.app/ui/docs/installation) for the `components.json` setup. Or use the [suiss/ui CLI](https://suiss.app/ui/docs/cli):

```bash title="Terminal"
npx @esuiss/ui@latest add charts pie-chart-nested --platform swift
```

**Jetpack Compose**

```bash title="Terminal"
npx shadcn@latest add @esuiss/pie-chart-nested
```

See [Installation](https://suiss.app/ui/docs/installation) for the `components.json` setup. Or use the [suiss/ui CLI](https://suiss.app/ui/docs/cli):

```bash title="Terminal"
npx @esuiss/ui@latest add charts pie-chart-nested --platform kotlin
```

**React Native**

The CLI also adds what it builds on: [Card](https://suiss.app/ui/docs/components/card), [Chart](https://suiss.app/ui/docs/components/chart).

**React Native, SwiftUI, Jetpack Compose**

**Manual**

**React Native**

**Uniwind**

1. Add the pieces it builds on: [Card](https://suiss.app/ui/docs/components/card), [Chart](https://suiss.app/ui/docs/components/chart).

2. Copy and paste the following code into `components/charts/pie-chart-nested.tsx`:

- `uniwind/components/charts/pie-chart-nested.tsx`: shown above

3. Update the import paths to match your project setup.

**NativeWind**

1. Add the pieces it builds on: [Card](https://suiss.app/ui/docs/components/card), [Chart](https://suiss.app/ui/docs/components/chart).

2. Copy and paste the following code into `components/charts/pie-chart-nested.tsx`:

```tsx title="nativewind/components/charts/pie-chart-nested.tsx"
import {
  Card,
  CardContent,
  CardDescription,
  CardHeader,
  CardTitle,
} from "@/components/ui/card"
import {
  type ChartConfig,
  ChartContainer,
  ChartTooltip,
  ChartTooltipContent,
  Pie,
  PieChart,
} from "@/components/ui/chart"

const chartData = [
  { device: "phone", users: 275 },
  { device: "laptop", users: 200 },
  { device: "tablet", users: 187 },
  { device: "watch", users: 173 },
  { device: "other", users: 90 },
]

const chartConfig = {
  users: { label: "Users" },
  phone: { label: "Phone", color: "chart-1" },
  laptop: { label: "Laptop", color: "chart-2" },
  tablet: { label: "Tablet", color: "chart-3" },
  watch: { label: "Watch", color: "chart-4" },
  other: { label: "Other", color: "chart-5" },
} satisfies ChartConfig

const groups = [
  { device: "phone", users: 475 },
  { device: "watch", users: 450 },
]

export function PieChartNested() {
  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>Nested</CardTitle>
        <CardDescription>Groups inside, details outside</CardDescription>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          accessibilityLabel="Nested"
          className="h-52 w-full"
        >
          <PieChart>
            <ChartTooltip
              cursor={false}
              content={<ChartTooltipContent hideLabel nameKey="device" />}
            />
            <Pie
              data={groups}
              dataKey="users"
              nameKey="device"
              outerRadius="52%"
              stroke="muted"
              strokeWidth={2}
              fillOpacity={0.55}
            />
            <Pie
              data={chartData}
              dataKey="users"
              nameKey="device"
              innerRadius="60%"
              outerRadius="86%"
              stroke="muted"
              strokeWidth={2}
            />
          </PieChart>
        </ChartContainer>
      </CardContent>
    </Card>
  )
}
```

3. Update the import paths to match your project setup.

**StyleSheet**

1. Add the pieces it builds on: [Card](https://suiss.app/ui/docs/components/card), [Chart](https://suiss.app/ui/docs/components/chart).

2. Copy and paste the following code into `components/charts/pie-chart-nested.tsx`:

```tsx title="stylesheet/components/charts/pie-chart-nested.tsx"
import {
  Card,
  CardContent,
  CardDescription,
  CardHeader,
  CardTitle,
} from "@/components/ui/card"
import {
  type ChartConfig,
  ChartContainer,
  ChartTooltip,
  ChartTooltipContent,
  Pie,
  PieChart,
} from "@/components/ui/chart"

const chartData = [
  { device: "phone", users: 275 },
  { device: "laptop", users: 200 },
  { device: "tablet", users: 187 },
  { device: "watch", users: 173 },
  { device: "other", users: 90 },
]

const chartConfig = {
  users: { label: "Users" },
  phone: { label: "Phone", color: "chart-1" },
  laptop: { label: "Laptop", color: "chart-2" },
  tablet: { label: "Tablet", color: "chart-3" },
  watch: { label: "Watch", color: "chart-4" },
  other: { label: "Other", color: "chart-5" },
} satisfies ChartConfig

const groups = [
  { device: "phone", users: 475 },
  { device: "watch", users: 450 },
]

export function PieChartNested() {
  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>Nested</CardTitle>
        <CardDescription>Groups inside, details outside</CardDescription>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          accessibilityLabel="Nested"
          style={{ height: 208 }}
        >
          <PieChart>
            <ChartTooltip
              cursor={false}
              content={<ChartTooltipContent hideLabel nameKey="device" />}
            />
            <Pie
              data={groups}
              dataKey="users"
              nameKey="device"
              outerRadius="52%"
              stroke="muted"
              strokeWidth={2}
              fillOpacity={0.55}
            />
            <Pie
              data={chartData}
              dataKey="users"
              nameKey="device"
              innerRadius="60%"
              outerRadius="86%"
              stroke="muted"
              strokeWidth={2}
            />
          </PieChart>
        </ChartContainer>
      </CardContent>
    </Card>
  )
}
```

3. Update the import paths to match your project setup.

**SwiftUI**

1. Target iOS 17 or later.

2. Copy the theme files every view uses:

- `swift/Theme/Theme.swift`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/swiftui/Sources/EsuissUI/Theme/Theme.swift)

- `swift/Theme/Tokens.swift`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/swiftui/Sources/EsuissUI/Theme/Tokens.swift)

3. Copy the source and every file it uses:

- `swift/Charts/PieChartNested.swift`: shown above

- `swift/Components/Card.swift`: see [Card](https://suiss.app/ui/docs/components/card.md)

- `swift/Components/Chart.swift`: see [Chart](https://suiss.app/ui/docs/components/chart.md)

- `swift/Components/Haptics.swift`: see [Haptics](https://suiss.app/ui/docs/components/haptics.md)

- `swift/Components/Item.swift`: see [Item](https://suiss.app/ui/docs/components/item.md)

- `swift/Components/Separator.swift`: see [Separator](https://suiss.app/ui/docs/components/separator.md)

4. Add the files to your app target.

**Jetpack Compose**

1. Apply the Compose compiler plugin, enable Compose, set `compileSdk` to 37 or higher and `minSdk` to 24 or higher, and add the dependencies:

```kotlin title="build.gradle.kts"
plugins {
    id("org.jetbrains.kotlin.plugin.compose")
}

android {
    compileSdk = 37
    defaultConfig { minSdk = 24 }
    buildFeatures { compose = true }
}

dependencies {
    implementation(platform("androidx.compose:compose-bom:2026.09.00"))
    implementation("androidx.compose.foundation:foundation")
    implementation("androidx.compose.ui:ui")
}
```

2. Copy the theme files every view uses:

- `kotlin/theme/Theme.kt`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/kotlin/ui/src/main/kotlin/com/esuiss/ui/theme/Theme.kt)

- `kotlin/theme/Tokens.kt`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/kotlin/ui/src/main/kotlin/com/esuiss/ui/theme/Tokens.kt)

3. Copy the source and every file it uses:

- `kotlin/charts/PieChartNested.kt`: shown above

- `kotlin/components/Card.kt`: see [Card](https://suiss.app/ui/docs/components/card.md)

- `kotlin/components/Chart.kt`: see [Chart](https://suiss.app/ui/docs/components/chart.md)

- `kotlin/components/Content.kt`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/kotlin/ui/src/main/kotlin/com/esuiss/ui/components/Content.kt)

- `kotlin/components/FormSupport.kt`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/kotlin/ui/src/main/kotlin/com/esuiss/ui/components/FormSupport.kt)

- `kotlin/components/Haptics.kt`: see [Haptics](https://suiss.app/ui/docs/components/haptics.md)

- `kotlin/components/Icon.kt`: see [Icon](https://suiss.app/ui/docs/components/icon.md)

4. Update the `com.esuiss.ui` package names to match your project.

**React Native, SwiftUI, Jetpack Compose**

### Usage

**React Native**

```tsx
import { PieChartNested } from "@/components/charts/pie-chart-nested"
```

```tsx
<PieChartNested />
```

**SwiftUI**

```swift
import SwiftUI

struct PieNestedExample: View {
  var body: some View {
    PieChartNested()
  }
}
```

**Jetpack Compose**

```kotlin
import androidx.compose.runtime.Composable
import com.esuiss.ui.charts.PieChartNested

@Composable
fun PieNestedExample() {
    PieChartNested()
}
```



## Pie Chart Separated

A donut whose slices are pulled apart with wide gaps and rounded corners.

Source: https://suiss.app/ui/docs/charts/pie-chart#separated

**React**

**Example**

```tsx title="components/charts/pie-chart-separated.tsx"
"use client"

import { Pie, PieChart } from "recharts"

import {
  Card,
  CardContent,
  CardDescription,
  CardHeader,
  CardTitle,
} from "@/components/ui/card"
import {
  type ChartConfig,
  ChartContainer,
  ChartTooltip,
  ChartTooltipContent,
} from "@/components/ui/chart"

const chartData = [
  { device: "phone", users: 275, fill: "var(--color-phone)" },
  { device: "laptop", users: 200, fill: "var(--color-laptop)" },
  { device: "tablet", users: 187, fill: "var(--color-tablet)" },
  { device: "watch", users: 173, fill: "var(--color-watch)" },
  { device: "other", users: 90, fill: "var(--color-other)" },
]

const chartConfig = {
  users: { label: "Users" },
  phone: { label: "Phone", color: "var(--chart-1)" },
  laptop: { label: "Laptop", color: "var(--chart-2)" },
  tablet: { label: "Tablet", color: "var(--chart-3)" },
  watch: { label: "Watch", color: "var(--chart-4)" },
  other: { label: "Other", color: "var(--chart-5)" },
} satisfies ChartConfig

export function PieChartSeparated() {
  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>Separated slices</CardTitle>
        <CardDescription>Gaps and rounded corners</CardDescription>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          className="aspect-auto h-52 w-full"
        >
          <PieChart accessibilityLayer>
            <ChartTooltip
              cursor={false}
              content={<ChartTooltipContent hideLabel nameKey="device" />}
            />
            <Pie
              data={chartData}
              dataKey="users"
              nameKey="device"
              innerRadius="55%"
              outerRadius="85%"
              paddingAngle={5}
              cornerRadius={8}
              strokeWidth={0}
            />
          </PieChart>
        </ChartContainer>
      </CardContent>
    </Card>
  )
}
```

A donut whose slices are pushed apart with wide gaps and rounded corners, giving each segment a tile-like look. Choose it for a softer, more decorative style than the standard donut.

Replace `chartData` and add each category to `chartConfig`. `paddingAngle` sets the spacing and `cornerRadius` the rounding; large values squeeze thin slices, so this style suits data without tiny values.

### Installation

**Command**

```bash title="Terminal"
npx shadcn@latest add @esuiss/pie-chart-separated
```

Works in any project with a `components.json`. See [Installation](https://suiss.app/ui/docs/installation#add-components) for the one-line registry setup. Or use the [suiss/ui CLI](https://suiss.app/ui/docs/cli):

```bash title="Terminal"
npx @esuiss/ui@latest add charts pie-chart-separated
```

**Manual**

1. Install the following dependencies:

```bash title="Terminal"
npm install recharts
```

2. Add the pieces it builds on: [Card](https://suiss.app/ui/docs/components/card), [Chart](https://suiss.app/ui/docs/components/chart).

3. Copy and paste the following code into your project.

```tsx title="components/charts/pie-chart-separated.tsx"
"use client"

import { Pie, PieChart } from "recharts"

import {
  Card,
  CardContent,
  CardDescription,
  CardHeader,
  CardTitle,
} from "@/components/ui/card"
import {
  type ChartConfig,
  ChartContainer,
  ChartTooltip,
  ChartTooltipContent,
} from "@/components/ui/chart"

const chartData = [
  { device: "phone", users: 275, fill: "var(--color-phone)" },
  { device: "laptop", users: 200, fill: "var(--color-laptop)" },
  { device: "tablet", users: 187, fill: "var(--color-tablet)" },
  { device: "watch", users: 173, fill: "var(--color-watch)" },
  { device: "other", users: 90, fill: "var(--color-other)" },
]

const chartConfig = {
  users: { label: "Users" },
  phone: { label: "Phone", color: "var(--chart-1)" },
  laptop: { label: "Laptop", color: "var(--chart-2)" },
  tablet: { label: "Tablet", color: "var(--chart-3)" },
  watch: { label: "Watch", color: "var(--chart-4)" },
  other: { label: "Other", color: "var(--chart-5)" },
} satisfies ChartConfig

export function PieChartSeparated() {
  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>Separated slices</CardTitle>
        <CardDescription>Gaps and rounded corners</CardDescription>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          className="aspect-auto h-52 w-full"
        >
          <PieChart accessibilityLayer>
            <ChartTooltip
              cursor={false}
              content={<ChartTooltipContent hideLabel nameKey="device" />}
            />
            <Pie
              data={chartData}
              dataKey="users"
              nameKey="device"
              innerRadius="55%"
              outerRadius="85%"
              paddingAngle={5}
              cornerRadius={8}
              strokeWidth={0}
            />
          </PieChart>
        </ChartContainer>
      </CardContent>
    </Card>
  )
}
```

4. Update the import paths to match your project setup.

### Usage

```tsx
import { PieChartSeparated } from "@/components/charts/pie-chart-separated"
```

```tsx
<PieChartSeparated />
```

**React Native, SwiftUI, Jetpack Compose**

```tsx title="uniwind/components/charts/pie-chart-separated.tsx"
import {
  Card,
  CardContent,
  CardDescription,
  CardHeader,
  CardTitle,
} from "@/components/ui/card"
import {
  type ChartConfig,
  ChartContainer,
  ChartTooltip,
  ChartTooltipContent,
  Pie,
  PieChart,
} from "@/components/ui/chart"

const chartData = [
  { device: "phone", users: 275 },
  { device: "laptop", users: 200 },
  { device: "tablet", users: 187 },
  { device: "watch", users: 173 },
  { device: "other", users: 90 },
]

const chartConfig = {
  users: { label: "Users" },
  phone: { label: "Phone", color: "chart-1" },
  laptop: { label: "Laptop", color: "chart-2" },
  tablet: { label: "Tablet", color: "chart-3" },
  watch: { label: "Watch", color: "chart-4" },
  other: { label: "Other", color: "chart-5" },
} satisfies ChartConfig

export function PieChartSeparated() {
  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>Separated slices</CardTitle>
        <CardDescription>Gaps and rounded corners</CardDescription>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          accessibilityLabel="Separated slices"
          className="h-52 w-full"
        >
          <PieChart>
            <ChartTooltip
              cursor={false}
              content={<ChartTooltipContent hideLabel nameKey="device" />}
            />
            <Pie
              data={chartData}
              dataKey="users"
              nameKey="device"
              innerRadius="55%"
              outerRadius="85%"
              paddingAngle={5}
              cornerRadius={8}
              strokeWidth={0}
            />
          </PieChart>
        </ChartContainer>
      </CardContent>
    </Card>
  )
}
```

```swift title="swift/Charts/PieChartSeparated.swift"
import Charts
import SwiftUI

private let chartData: [(device: String, users: Double)] = [
  ("phone", 275), ("laptop", 200), ("tablet", 187), ("watch", 173), ("other", 90),
]

private let chartConfig: ChartConfig = [
  "users": .init("Users"),
  "phone": .init("Phone", color: EsuissColor.chart1),
  "laptop": .init("Laptop", color: EsuissColor.chart2),
  "tablet": .init("Tablet", color: EsuissColor.chart3),
  "watch": .init("Watch", color: EsuissColor.chart4),
  "other": .init("Other", color: EsuissColor.chart5),
]

public struct PieChartSeparated: View {
  @State private var selection: Int?

  public init() {}

  public var body: some View {
    Card(.filled, size: .sm) {
      CardHeader("Separated slices", description: "Gaps and rounded corners")
      CardContent {
        ChartContainer(config: chartConfig) {
          ChartAnimator { progress in
            Chart {
              ForEach(chartData, id: \.device) { item in
                SectorMark(angle: .value("Users", item.users * progress), innerRadius: .ratio(0.55), outerRadius: .ratio(0.85), angularInset: 3)
                  .cornerRadius(8)
                  .foregroundStyle(chartConfig.color(item.device))
              }
              ChartSectorRest(total: chartData.reduce(0) { $0 + $1.users }, progress: progress)
            }
            .chartTooltip(
              angle: chartData.map(\.users),
              labels: chartData.map { chartConfig.label($0.device) },
              innerRadius: 0.55,
              outerRadius: 0.85,
              selection: $selection,
              accessibilityLabel: "Separated slices",
              items: { [ChartTooltipItem(chartData[$0].device, value: chartData[$0].users)] }
            ) { payload in
              ChartTooltipContent(payload, hideLabel: true)
            }
            .padding(5)
          }
        }
        .frame(height: 208)
      }
    }
  }
}
```

```kt title="kotlin/charts/PieChartSeparated.kt"
package com.esuiss.ui.charts

import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.esuiss.ui.components.Card
import com.esuiss.ui.components.CardContent
import com.esuiss.ui.components.CardHeader
import com.esuiss.ui.components.CardSize
import com.esuiss.ui.components.CardVariant
import com.esuiss.ui.components.ChartConfig
import com.esuiss.ui.components.ChartConfigItem
import com.esuiss.ui.components.ChartContainer
import com.esuiss.ui.components.ChartTooltipContent
import com.esuiss.ui.components.PieChart

private class PieSeparatedDeviceUsers(val device: String, val users: Double)

private val chartData = listOf(
    PieSeparatedDeviceUsers("phone", 275.0),
    PieSeparatedDeviceUsers("laptop", 200.0),
    PieSeparatedDeviceUsers("tablet", 187.0),
    PieSeparatedDeviceUsers("watch", 173.0),
    PieSeparatedDeviceUsers("other", 90.0),
)

private val chartConfig = ChartConfig(
    "users" to ChartConfigItem("Users"),
    "phone" to ChartConfigItem("Phone") { chart1 },
    "laptop" to ChartConfigItem("Laptop") { chart2 },
    "tablet" to ChartConfigItem("Tablet") { chart3 },
    "watch" to ChartConfigItem("Watch") { chart4 },
    "other" to ChartConfigItem("Other") { chart5 },
)

@Composable
fun PieChartSeparated(modifier: Modifier = Modifier) {
    Card(modifier, variant = CardVariant.Filled, size = CardSize.Sm) {
        CardHeader("Separated slices", description = "Gaps and rounded corners")
        CardContent {
            ChartContainer(
                chartConfig,
                Modifier
                    .fillMaxWidth()
                    .height(208.dp),
            ) {
                PieChart(accessibilityLabel = "Separated slices") {
                    ChartTooltip { ChartTooltipContent(hideLabel = true) }
                    Pie(
                        chartData,
                        value = { it.users },
                        nameKey = { it.device },
                        innerRadius = 0.55f,
                        outerRadius = 0.85f,
                        paddingAngle = 5f,
                        cornerRadius = 8.dp,
                        strokeWidth = 0.dp,
                    )
                }
            }
        }
    }
}
```

**React Native, Jetpack Compose**

A `PieChart` donut with `paddingAngle` and `cornerRadius` set so each slice stands apart. `chartData` holds one record per device with a `users` count. Pressing a slice shows a tooltip.

**React Native**

Replace `chartData` with your records and keep `dataKey` and `nameKey` in step with your field names. Add one entry per slice to `chartConfig` with its label and color; the component takes no props.

**React Native, SwiftUI, Jetpack Compose**

### Installation

**Command**

**React Native**

```bash title="Terminal"
npx shadcn@latest add @esuiss/pie-chart-separated
```

See [Installation](https://suiss.app/ui/docs/installation) for the `components.json` setup. Or use the [suiss/ui CLI](https://suiss.app/ui/docs/cli):

```bash title="Terminal"
npx @esuiss/ui@latest add charts pie-chart-separated
```

**SwiftUI**

```bash title="Terminal"
npx shadcn@latest add @esuiss/pie-chart-separated
```

See [Installation](https://suiss.app/ui/docs/installation) for the `components.json` setup. Or use the [suiss/ui CLI](https://suiss.app/ui/docs/cli):

```bash title="Terminal"
npx @esuiss/ui@latest add charts pie-chart-separated --platform swift
```

**Jetpack Compose**

```bash title="Terminal"
npx shadcn@latest add @esuiss/pie-chart-separated
```

See [Installation](https://suiss.app/ui/docs/installation) for the `components.json` setup. Or use the [suiss/ui CLI](https://suiss.app/ui/docs/cli):

```bash title="Terminal"
npx @esuiss/ui@latest add charts pie-chart-separated --platform kotlin
```

**React Native**

The CLI also adds what it builds on: [Card](https://suiss.app/ui/docs/components/card), [Chart](https://suiss.app/ui/docs/components/chart).

**React Native, SwiftUI, Jetpack Compose**

**Manual**

**React Native**

**Uniwind**

1. Add the pieces it builds on: [Card](https://suiss.app/ui/docs/components/card), [Chart](https://suiss.app/ui/docs/components/chart).

2. Copy and paste the following code into `components/charts/pie-chart-separated.tsx`:

- `uniwind/components/charts/pie-chart-separated.tsx`: shown above

3. Update the import paths to match your project setup.

**NativeWind**

1. Add the pieces it builds on: [Card](https://suiss.app/ui/docs/components/card), [Chart](https://suiss.app/ui/docs/components/chart).

2. Copy and paste the following code into `components/charts/pie-chart-separated.tsx`:

```tsx title="nativewind/components/charts/pie-chart-separated.tsx"
import {
  Card,
  CardContent,
  CardDescription,
  CardHeader,
  CardTitle,
} from "@/components/ui/card"
import {
  type ChartConfig,
  ChartContainer,
  ChartTooltip,
  ChartTooltipContent,
  Pie,
  PieChart,
} from "@/components/ui/chart"

const chartData = [
  { device: "phone", users: 275 },
  { device: "laptop", users: 200 },
  { device: "tablet", users: 187 },
  { device: "watch", users: 173 },
  { device: "other", users: 90 },
]

const chartConfig = {
  users: { label: "Users" },
  phone: { label: "Phone", color: "chart-1" },
  laptop: { label: "Laptop", color: "chart-2" },
  tablet: { label: "Tablet", color: "chart-3" },
  watch: { label: "Watch", color: "chart-4" },
  other: { label: "Other", color: "chart-5" },
} satisfies ChartConfig

export function PieChartSeparated() {
  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>Separated slices</CardTitle>
        <CardDescription>Gaps and rounded corners</CardDescription>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          accessibilityLabel="Separated slices"
          className="h-52 w-full"
        >
          <PieChart>
            <ChartTooltip
              cursor={false}
              content={<ChartTooltipContent hideLabel nameKey="device" />}
            />
            <Pie
              data={chartData}
              dataKey="users"
              nameKey="device"
              innerRadius="55%"
              outerRadius="85%"
              paddingAngle={5}
              cornerRadius={8}
              strokeWidth={0}
            />
          </PieChart>
        </ChartContainer>
      </CardContent>
    </Card>
  )
}
```

3. Update the import paths to match your project setup.

**StyleSheet**

1. Add the pieces it builds on: [Card](https://suiss.app/ui/docs/components/card), [Chart](https://suiss.app/ui/docs/components/chart).

2. Copy and paste the following code into `components/charts/pie-chart-separated.tsx`:

```tsx title="stylesheet/components/charts/pie-chart-separated.tsx"
import {
  Card,
  CardContent,
  CardDescription,
  CardHeader,
  CardTitle,
} from "@/components/ui/card"
import {
  type ChartConfig,
  ChartContainer,
  ChartTooltip,
  ChartTooltipContent,
  Pie,
  PieChart,
} from "@/components/ui/chart"

const chartData = [
  { device: "phone", users: 275 },
  { device: "laptop", users: 200 },
  { device: "tablet", users: 187 },
  { device: "watch", users: 173 },
  { device: "other", users: 90 },
]

const chartConfig = {
  users: { label: "Users" },
  phone: { label: "Phone", color: "chart-1" },
  laptop: { label: "Laptop", color: "chart-2" },
  tablet: { label: "Tablet", color: "chart-3" },
  watch: { label: "Watch", color: "chart-4" },
  other: { label: "Other", color: "chart-5" },
} satisfies ChartConfig

export function PieChartSeparated() {
  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>Separated slices</CardTitle>
        <CardDescription>Gaps and rounded corners</CardDescription>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          accessibilityLabel="Separated slices"
          style={{ height: 208 }}
        >
          <PieChart>
            <ChartTooltip
              cursor={false}
              content={<ChartTooltipContent hideLabel nameKey="device" />}
            />
            <Pie
              data={chartData}
              dataKey="users"
              nameKey="device"
              innerRadius="55%"
              outerRadius="85%"
              paddingAngle={5}
              cornerRadius={8}
              strokeWidth={0}
            />
          </PieChart>
        </ChartContainer>
      </CardContent>
    </Card>
  )
}
```

3. Update the import paths to match your project setup.

**SwiftUI**

1. Target iOS 17 or later.

2. Copy the theme files every view uses:

- `swift/Theme/Theme.swift`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/swiftui/Sources/EsuissUI/Theme/Theme.swift)

- `swift/Theme/Tokens.swift`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/swiftui/Sources/EsuissUI/Theme/Tokens.swift)

3. Copy the source and every file it uses:

- `swift/Charts/PieChartSeparated.swift`: shown above

- `swift/Components/Card.swift`: see [Card](https://suiss.app/ui/docs/components/card.md)

- `swift/Components/Chart.swift`: see [Chart](https://suiss.app/ui/docs/components/chart.md)

- `swift/Components/Haptics.swift`: see [Haptics](https://suiss.app/ui/docs/components/haptics.md)

- `swift/Components/Item.swift`: see [Item](https://suiss.app/ui/docs/components/item.md)

- `swift/Components/Separator.swift`: see [Separator](https://suiss.app/ui/docs/components/separator.md)

4. Add the files to your app target.

**Jetpack Compose**

1. Apply the Compose compiler plugin, enable Compose, set `compileSdk` to 37 or higher and `minSdk` to 24 or higher, and add the dependencies:

```kotlin title="build.gradle.kts"
plugins {
    id("org.jetbrains.kotlin.plugin.compose")
}

android {
    compileSdk = 37
    defaultConfig { minSdk = 24 }
    buildFeatures { compose = true }
}

dependencies {
    implementation(platform("androidx.compose:compose-bom:2026.09.00"))
    implementation("androidx.compose.foundation:foundation")
    implementation("androidx.compose.ui:ui")
}
```

2. Copy the theme files every view uses:

- `kotlin/theme/Theme.kt`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/kotlin/ui/src/main/kotlin/com/esuiss/ui/theme/Theme.kt)

- `kotlin/theme/Tokens.kt`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/kotlin/ui/src/main/kotlin/com/esuiss/ui/theme/Tokens.kt)

3. Copy the source and every file it uses:

- `kotlin/charts/PieChartSeparated.kt`: shown above

- `kotlin/components/Card.kt`: see [Card](https://suiss.app/ui/docs/components/card.md)

- `kotlin/components/Chart.kt`: see [Chart](https://suiss.app/ui/docs/components/chart.md)

- `kotlin/components/Content.kt`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/kotlin/ui/src/main/kotlin/com/esuiss/ui/components/Content.kt)

- `kotlin/components/FormSupport.kt`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/kotlin/ui/src/main/kotlin/com/esuiss/ui/components/FormSupport.kt)

- `kotlin/components/Haptics.kt`: see [Haptics](https://suiss.app/ui/docs/components/haptics.md)

- `kotlin/components/Icon.kt`: see [Icon](https://suiss.app/ui/docs/components/icon.md)

4. Update the `com.esuiss.ui` package names to match your project.

**React Native, SwiftUI, Jetpack Compose**

### Usage

**React Native**

```tsx
import { PieChartSeparated } from "@/components/charts/pie-chart-separated"
```

```tsx
<PieChartSeparated />
```

**SwiftUI**

```swift
import SwiftUI

struct PieSeparatedExample: View {
  var body: some View {
    PieChartSeparated()
  }
}
```

**Jetpack Compose**

```kotlin
import androidx.compose.runtime.Composable
import com.esuiss.ui.charts.PieChartSeparated

@Composable
fun PieSeparatedExample() {
    PieChartSeparated()
}
```

