Leave Yamada UI a star

Star
Yamada UIYamada UIv1.5.1

RadialChart

RadialChart is a component for drawing radial charts to compare multiple sets of data.

Source@yamada-ui/charts

Import

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

Usage

Editable example

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

return <RadialChart data={data} />
Copied!

Change Size

Editable example

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

return (
  <VStack>
    <RadialChart data={data} size="sm" />
    <RadialChart data={data} size="md" />
    <RadialChart data={data} size="lg" />
    <RadialChart data={data} size="full" />
  </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 data = useMemo(
  () => [
    { name: "HP", value: 106, color: "green.500" },
    { name: "こうげき", value: 90, color: "red.500" },
    { name: "ぼうぎょ", value: 130, color: "blue.500" },
    { name: "とくこう", value: 90, color: "purple.500" },
    { name: "とくぼう", value: 154, color: "orange.500" },
    { name: "すばやさ", value: 110, color: "cyan.500" },
  ],
  [],
)

return (
  <VStack>
    <RadialChart data={data} withLegend />

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

Adjust Spacing

To adjust the spacing, set barCategoryGap in radialBarProps.

Editable example

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

return (
  <RadialChart
    data={data}
    interRadius={30}
    chartProps={{
      barCategoryGap: "30%",
    }}
  />
)
Copied!

Adjust Inner and Outer Radius

To adjust the inner radius, set innerRadius, and for the outer radius, set outerRadius with either a percentage or a numerical value.

Editable example

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

return (
  <VStack>
    <RadialChart data={data} innerRadius="30%" />
    <RadialChart data={data} outerRadius="70%" />
  </VStack>
)
Copied!

Adjust Start and End Angles

To adjust the start angle, set startAngle, and for the end angle, set endAngle.

Editable example

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

return <RadialChart data={data} startAngle={180} endAngle={0} />
Copied!

Display Labels

To display labels, set the locations and values of the labels you want to show in labelListProps as an array.

Editable example

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

return (
  <RadialChart
    data={data}
    innerRadius={50}
    endAngle={-225}
    labelListProps={[
      {
        position: "insideStart",
        dataKey: "name",
      },
      {
        position: "insideEnd",
        dataKey: "value",
      },
    ]}
  />
)
Copied!

Switch Data Displayed in Tooltip

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

Editable example

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

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

Hide Tooltip

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

Editable example

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

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

Format

To format the values in the tooltip, use valueFormatter.

Editable example

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

return <RadialChart data={data} valueFormatter={(value) => `${value}P`} />
Copied!

Adjust Opacity

To adjust the opacity, set fillOpacity with either a numerical value or an array of numbers.

Editable example

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

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

Display Grid

To display the grid, set withPolarGrid to true.

To change the shape of the grid, set polarGridProps.gridType to either "polygon" or "circle". The default is "polygon".

Editable example

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

return (
  <VStack>
    <RadialChart data={data} withPolarGrid endAngle={-270} />
    <RadialChart
      data={data}
      withPolarGrid
      endAngle={-270}
      polarGridProps={{ gridType: "circle" }}
    />
  </VStack>
)
Copied!

Display Background

To display the background, set radialBarProps.background with fill.

Editable example

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

return (
  <RadialChart
    data={data}
    radialBarProps={{
      background: { fill: ["blackAlpha.200", "whiteAlpha.100"] },
    }}
  />
)
Copied!

Edit this page on GitHub

PreviousRadarChartNextCarousel