Leave Yamada UI a star

Star
Yamada UIYamada UIv1.7.2

PieChart

PieChart is a component for drawing pie charts to compare multiple sets of data.

Source@yamada-ui/charts

Import

pnpm add @yamada-ui/charts
Copied!
import { PieChart } from "@yamada-ui/charts"
Copied!

Usage

Editable example

const mewtwo: CellProps[] = useMemo(
  () => [
    {
      name: "HP",
      value: 106,
      color: "green.500",
    },
    {
      name: "こうげき",
      value: 110,
      color: "red.500",
    },
    {
      name: "ぼうぎょ",
      value: 90,
      color: "blue.500",
    },
    {
      name: "とくこう",
      value: 154,
      color: "purple.500",
    },
    {
      name: "とくぼう",
      value: 90,
      color: "orange.500",
    },
    {
      name: "すばやさ",
      value: 130,
      color: "cyan.500",
    },
  ],
  [],
)

return <PieChart data={mewtwo} />
Copied!

Change Size

Editable example

const mewtwo: CellProps[] = useMemo(
  () => [
    {
      name: "HP",
      value: 106,
      color: "green.500",
    },
    {
      name: "こうげき",
      value: 110,
      color: "red.500",
    },
    {
      name: "ぼうぎょ",
      value: 90,
      color: "blue.500",
    },
    {
      name: "とくこう",
      value: 154,
      color: "purple.500",
    },
    {
      name: "とくぼう",
      value: 90,
      color: "orange.500",
    },
    {
      name: "すばやさ",
      value: 130,
      color: "cyan.500",
    },
  ],
  [],
)

return (
  <VStack>
    <PieChart data={mewtwo} size="sm" />
    <PieChart data={mewtwo} size="md" />
    <PieChart data={mewtwo} size="lg" />
  </VStack>
)
Copied!

Display Legend

To display the legend, set withLegend to true. To change the position of the legend, set legendProps.verticalAlign to "bottom" or similar.

Editable example

const mewtwo: CellProps[] = useMemo(
  () => [
    {
      name: "HP",
      value: 106,
      color: "green.500",
    },
    {
      name: "こうげき",
      value: 110,
      color: "red.500",
    },
    {
      name: "ぼうぎょ",
      value: 90,
      color: "blue.500",
    },
    {
      name: "とくこう",
      value: 154,
      color: "purple.500",
    },
    {
      name: "とくぼう",
      value: 90,
      color: "orange.500",
    },
    {
      name: "すばやさ",
      value: 130,
      color: "cyan.500",
    },
  ],
  [],
)

return (
  <VStack>
    <PieChart data={mewtwo} withLegend />

    <PieChart
      data={mewtwo}
      withLegend
      legendProps={{ verticalAlign: "bottom", mb: "0", mt: "4" }}
    />
  </VStack>
)
Copied!

Adjust spacing

To adjust spacing, set paddingAngle to a number.

Editable example

const mewtwo: CellProps[] = useMemo(
  () => [
    {
      name: "HP",
      value: 106,
      color: "green.500",
    },
    {
      name: "こうげき",
      value: 110,
      color: "red.500",
    },
    {
      name: "ぼうぎょ",
      value: 90,
      color: "blue.500",
    },
    {
      name: "とくこう",
      value: 154,
      color: "purple.500",
    },
    {
      name: "とくぼう",
      value: 90,
      color: "orange.500",
    },
    {
      name: "すばやさ",
      value: 130,
      color: "cyan.500",
    },
  ],
  [],
)

return <PieChart data={mewtwo} paddingAngle={15} />
Copied!

Adjust start angle, end angle

Set an angle to startAngle to adjust start angle or endAngle to adjust end angle.

Editable example

const mewtwo: CellProps[] = useMemo(
  () => [
    {
      name: "HP",
      value: 106,
      color: "green.500",
    },
    {
      name: "こうげき",
      value: 110,
      color: "red.500",
    },
    {
      name: "ぼうぎょ",
      value: 90,
      color: "blue.500",
    },
    {
      name: "とくこう",
      value: 154,
      color: "purple.500",
    },
    {
      name: "とくぼう",
      value: 90,
      color: "orange.500",
    },
    {
      name: "すばやさ",
      value: 130,
      color: "cyan.500",
    },
  ],
  [],
)

return <PieChart data={mewtwo} startAngle={90} endAngle={225} />
Copied!

Display Labels

To display the labels, set withLabels to true.
To display guide to labels, set withLabelLines to true.

Editable example

const mewtwo: CellProps[] = useMemo(
  () => [
    {
      name: "HP",
      value: 106,
      color: "green.500",
    },
    {
      name: "こうげき",
      value: 110,
      color: "red.500",
    },
    {
      name: "ぼうぎょ",
      value: 90,
      color: "blue.500",
    },
    {
      name: "とくこう",
      value: 154,
      color: "purple.500",
    },
    {
      name: "とくぼう",
      value: 90,
      color: "orange.500",
    },
    {
      name: "すばやさ",
      value: 130,
      color: "cyan.500",
    },
  ],
  [],
)

return <PieChart data={mewtwo} withLabels withLabelLines />
Copied!

Adjust label position

To adjust label position, set labelOffset to a number.

Editable example

const mewtwo: CellProps[] = useMemo(
  () => [
    {
      name: "HP",
      value: 106,
      color: "green.500",
    },
    {
      name: "こうげき",
      value: 110,
      color: "red.500",
    },
    {
      name: "ぼうぎょ",
      value: 90,
      color: "blue.500",
    },
    {
      name: "とくこう",
      value: 154,
      color: "purple.500",
    },
    {
      name: "とくぼう",
      value: 90,
      color: "orange.500",
    },
    {
      name: "すばやさ",
      value: 130,
      color: "cyan.500",
    },
  ],
  [],
)

return <PieChart data={mewtwo} withLabels withLabelLines labelOffset={35} />
Copied!

Make Proportional

To display the label as a percentage, set isPercent to true. The default is false.

Editable example

const mewtwo: CellProps[] = useMemo(
  () => [
    {
      name: "HP",
      value: 106,
      color: "green.500",
    },
    {
      name: "こうげき",
      value: 110,
      color: "red.500",
    },
    {
      name: "ぼうぎょ",
      value: 90,
      color: "blue.500",
    },
    {
      name: "とくこう",
      value: 154,
      color: "purple.500",
    },
    {
      name: "とくぼう",
      value: 90,
      color: "orange.500",
    },
    {
      name: "すばやさ",
      value: 130,
      color: "cyan.500",
    },
  ],
  [],
)

return <PieChart data={mewtwo} withLabels isPercent />
Copied!

Switching the data displayed in the tooltip

To switch the data displayed in the tooltip, set tooltipDataSource to all or segment . The default is all.

Editable example

const mewtwo: CellProps[] = useMemo(
  () => [
    {
      name: "HP",
      value: 106,
      color: "green.500",
    },
    {
      name: "こうげき",
      value: 110,
      color: "red.500",
    },
    {
      name: "ぼうぎょ",
      value: 90,
      color: "blue.500",
    },
    {
      name: "とくこう",
      value: 154,
      color: "purple.500",
    },
    {
      name: "とくぼう",
      value: 90,
      color: "orange.500",
    },
    {
      name: "すばやさ",
      value: 130,
      color: "cyan.500",
    },
  ],
  [],
)

return <PieChart data={mewtwo} tooltipDataSource="segment" />
Copied!

Hide Tooltip

To hide the tooltip, set withTooltip to false. The default is true.

Editable example

const mewtwo: CellProps[] = useMemo(
  () => [
    {
      name: "HP",
      value: 106,
      color: "green.500",
    },
    {
      name: "こうげき",
      value: 110,
      color: "red.500",
    },
    {
      name: "ぼうぎょ",
      value: 90,
      color: "blue.500",
    },
    {
      name: "とくこう",
      value: 154,
      color: "purple.500",
    },
    {
      name: "とくぼう",
      value: 90,
      color: "orange.500",
    },
    {
      name: "すばやさ",
      value: 130,
      color: "cyan.500",
    },
  ],
  [],
)

return <PieChart data={mewtwo} withTooltip={false} />
Copied!

Format

To format tooltip values, use valueFormatter.
To format label values, use labelFormatter.

Editable example

const mewtwo: CellProps[] = useMemo(
  () => [
    {
      name: "HP",
      value: 106,
      color: "green.500",
    },
    {
      name: "こうげき",
      value: 110,
      color: "red.500",
    },
    {
      name: "ぼうぎょ",
      value: 90,
      color: "blue.500",
    },
    {
      name: "とくこう",
      value: 154,
      color: "purple.500",
    },
    {
      name: "とくぼう",
      value: 90,
      color: "orange.500",
    },
    {
      name: "すばやさ",
      value: 130,
      color: "cyan.500",
    },
  ],
  [],
)

return (
  <VStack>
    <PieChart data={mewtwo} valueFormatter={(value) => `${value}P`} />
    <PieChart
      data={mewtwo}
      withLabels
      labelFormatter={(value) => `${value}P`}
    />
  </VStack>
)
Copied!

Adjust Opacity

To adjust opacity, set fillOpacity to a number or an array of numbers.

Editable example

const mewtwo: CellProps[] = useMemo(
  () => [
    {
      name: "HP",
      value: 106,
      color: "green.500",
    },
    {
      name: "こうげき",
      value: 110,
      color: "red.500",
    },
    {
      name: "ぼうぎょ",
      value: 90,
      color: "blue.500",
    },
    {
      name: "とくこう",
      value: 154,
      color: "purple.500",
    },
    {
      name: "とくぼう",
      value: 90,
      color: "orange.500",
    },
    {
      name: "すばやさ",
      value: 130,
      color: "cyan.500",
    },
  ],
  [],
)

return <PieChart data={mewtwo} fillOpacity={[0.8, 0.7]} />
Copied!

Edit this page on GitHub

PreviousBarChartNextDonutChart