본문으로 바로가기 본문 바로가기
WIKI 기술 지식 베이스

Charts - 방사형 막대

원문 보기 위키 갱신

Charts - 방사형 막대 (Radial Bars)

방사형 막대 차트를 사용해 주기적 카테고리를 따라 값을 비교합니다.

출처: MUI X documentation

본문

개요 (Overview)

방사형 막대 차트는 극좌표에서 값을 표시하며, 각 막대는 공통 중심에서 반지름 방향으로 자랍니다. 이 원형 레이아웃은 달, 하루의 시간, 나침반 방향 같은 주기적이거나 순환적인 데이터를 자연스럽게 읽을 수 있게 하고, 직선 축을 늘어뜨릴 중간 크기의 막대 데이터셋에 대해 컴팩트한 표시를 제공합니다.

아래 차트는 2013년과 2025년 사이 유럽에서 타인에 대한 평균 신뢰(16세 이상 인구)를 비교합니다.

import * as React from 'react';
import Box from '@mui/material/Box';
import Link from '@mui/material/Link';
import Typography from '@mui/material/Typography';
import { RadialBarChart } from '@mui/x-charts-premium/RadialBarChart';
import { europeanYouthTrust } from '../dataset/europeanYouthTrust';
import {
  EuAverageRing,
  PreviousTrustData,
  TrustLegend,
  TrustTooltip,
} from './trustRadialBarChartComponents';

const COLOR_2025 = '#1976d2';
const COLOR_2013 = '#d32f2f';

const trustFormatter = (value: number | null) =>
  value == null ? '' : `${value.toFixed(1)} / 10`;

const highlightScope = { highlight: 'item', fade: 'none' } as const;

export default function TrustRadialBarChart() {
  return (
    <div style={{ width: '100%' }}>
      <Typography variant="h6" align="center">
        Trust in others across Europe
      </Typography>
      <Typography variant="body2" align="center" color="text.secondary">
        Average rating (0–10), 2013 vs 2025
      </Typography>
      <Box sx={{ position: 'relative', mt: { xs: 1, sm: 2 } }}>
        <Box sx={{ height: { xs: 340, sm: 550 } }}>
          <RadialBarChart
            dataset={europeanYouthTrust}
            margin={{ top: 24, bottom: 24, left: 60, right: 60 }}
            hideLegend
            slots={{ tooltip: TrustTooltip }}
            series={[
              {
                dataKey: 'trust2025',
                label: '2025 trust',
                color: COLOR_2025,
                highlightScope,
                valueFormatter: trustFormatter,
              },
            ]}
            rotationAxis={[
              {
                scaleType: 'band',
                dataKey: 'country',
                startAngle: 0,
                endAngle: 354,
                categoryGapRatio: 0.25,
              },
            ]}
            radiusAxis={[
              {
                scaleType: 'linear',
                min: 0,
                max: 10,
                minRadius: '40%',
                tickInterval: [2, 4, 6, 8, 10],
              },
            ]}
            grid={{ radius: true }}
          >
            <EuAverageRing />
            <PreviousTrustData
              currentColor={COLOR_2025}
              previousColor={COLOR_2013}
            />
          </RadialBarChart>
        </Box>
        <TrustLegend currentColor={COLOR_2025} previousColor={COLOR_2013} />
      </Box>
      <Typography
        variant="caption"
        align="center"
        color="text.secondary"
        component="p"
        sx={{ mt: 2 }}
      >
        Source:{' '}
        <Link
          href="https://ec.europa.eu/eurostat/databrowser/view/ilc_pw03/default/table"
          target="_blank"
          rel="noopener"
        >
          Eurostat
        </Link>
      </Typography>
    </div>
  );
}

기본 (Basics)

RadialBarChart는 BarChart와 유사하지만 극좌표를 사용합니다. xAxis와 yAxis가 rotationAxis와 radiusAxis로 대체됩니다.

import * as React from 'react';
import { RadialBarChart } from '@mui/x-charts-premium/RadialBarChart';

const months = [
  'Jan',
  'Feb',
  'Mar',
  'Apr',
  'May',
  'Jun',
  'Jul',
  'Aug',
  'Sep',
  'Oct',
  'Nov',
  'Dec',
];
const highlightScope = { highlight: 'item', fade: 'global' } as const;

export default function BasicRadialBarChart() {
  return (
    <RadialBarChart
      height={400}
      series={[
        {
          data: [3, 5, 7, null, 12, 15, 18, 16, 13, 9, 6, 4],
          label: 'Temperature',
          highlightScope,
        },

        {
          data: [12, 15, 18, 16, 13, null, 6, 4, 3, 5, 7, 9],
          label: 'Temperature',
          stack: 'a',
          highlightScope,
        },
        {
          data: [7, 9, 12, 15, 18, 16, 13, null, 6, 4, 3, 5],
          label: 'Temperature',
          stack: 'a',
          highlightScope,
        },
      ]}
      rotationAxis={[{ scaleType: 'band', data: months }]}
      radiusAxis={[{ scaleType: 'linear', minRadius: 20, position: 'none' }]}
      grid={{ rotation: true, radius: true }}
    />
  );
}

공통 표시 옵션 (Common display options)

방사형 막대 차트는 막대 차트와 동일한 표시 옵션을 받습니다:

  • stack: 같은 stack 속성을 가진 series는 서로 위에 쌓입니다.
  • layout: 값을 나타내는 데 사용되는 축을 바꿉니다. 기본값('vertical')에서는 반지름이 값을 나타냅니다. layout='horizontal'이면 회전(rotation)이 값을 나타냅니다.
  • categoryGapRatio와 barGapRatio를 band 축에서 사용해 카테고리 사이와 카테고리 내 막대 사이의 간격을 제어할 수 있습니다.

아래 데모는 이러한 옵션을 보여 줍니다.

import * as React from 'react';
import Typography from '@mui/material/Typography';
import ChartsUsageDemo from 'docs/src/modules/components/ChartsUsageDemo';
import { RadialBarChart } from '@mui/x-charts-premium/RadialBarChart';
import { balanceSheet, addLabels } from '../bars/netflixsBalanceSheet';

const baseSeries = addLabels([
  { dataKey: 'totAss' },
  { dataKey: 'totLia' },
  { dataKey: 'totEq' },
]);

export default function RadialBarConfig() {
  return (
    <ChartsUsageDemo
      componentName="RadialBarChart"
      data={{
        layout: {
          knob: 'select',
          options: ['vertical', 'horizontal'],
          defaultValue: 'vertical',
        },
        stack: {
          knob: 'switch',
          defaultValue: true,
        },
        categoryGapRatio: {
          knob: 'number',
          defaultValue: 0.3,
          step: 0.1,
          min: 0,
          max: 1,
        },
        barGapRatio: {
          knob: 'number',
          defaultValue: 0.1,
          step: 0.1,
          min: -1,
          max: 1,
        },
      }}
      renderDemo={(props) => {
        const series = baseSeries.map((s, index) => ({
          ...s,
          layout: props.layout as 'vertical' | 'horizontal',
          ...(props.stack && index > 0 ? { stack: 'passive' } : {}),
        }));

        const bandAxis = {
          dataKey: 'year',
          scaleType: 'band' as const,
          categoryGapRatio: props.categoryGapRatio,
          barGapRatio: props.barGapRatio,
        };

        return (
          <div style={{ width: '100%' }}>
            <Typography>Netflix balance sheet</Typography>
            <RadialBarChart
              dataset={balanceSheet}
              series={series}
              height={400}
              rotationAxis={
                props.layout === 'vertical'
                  ? [bandAxis]
                  : [
                      {
                        scaleType: 'linear',
                        endAngle: 270,
                        valueFormatter(value, context) {
                          if (context.location === 'tick') {
                            return `${value / 1_000_000}M`;
                          }
                          return `${value / 1_000}k`;
                        },
                      },
                    ]
              }
              radiusAxis={
                props.layout === 'horizontal'
                  ? [bandAxis]
                  : [
                      {
                        scaleType: 'linear',
                        minRadius: 20,
                        position: 'none',
                        valueFormatter(value, context) {
                          if (context.location === 'tick') {
                            return `${value / 1_000_000}M`;
                          }
                          return `${value / 1_000}k`;
                        },
                      },
                    ]
              }
              grid={{ rotation: true, radius: true }}
            />
          </div>
        );
      }}
      getCode={({ props }) => {
        const stackProp = props.stack ? `, stack: 'passive'` : '';
        const bandAxis = `[
    {
      scaleType: 'band',
      data: ['2020', '2021', '2022', '2023'],
      categoryGapRatio: ${props.categoryGapRatio},
      barGapRatio: ${props.barGapRatio},
    },
  ]`;
        return `import { RadialBarChart } from '@mui/x-charts-premium/RadialBarChart';

<RadialBarChart
  // ...
  series={[
    { dataKey: 'totAss', layout: '${props.layout}' },
    { dataKey: 'totLia', layout: '${props.layout}'${stackProp} },
    { dataKey: 'totEq', layout: '${props.layout}'${stackProp} },
  ]}
  ${props.layout === 'horizontal' ? 'radiusAxis' : 'rotationAxis'}={${bandAxis}}
/>`;
      }}
    />
  );
}

각 막대 색칠 (Coloring each bar)

방사형 막대는 막대 차트와 동일한 색상 스케일을 지원합니다. 유일한 차이는 데카르트 x와 y 축이 rotationAxis와 radiusAxis로 대체된다는 것으로, 둘 중 하나에 colorMap을 설정할 수 있습니다.

아래 데모는 radiusAxis에 'ordinal' 색상 맵을 설정해 각 지표 링이 목표를 향한 진행 상황을 추적하는 건강 대시보드를 만듭니다.

import * as React from 'react';
import { RadialBarChart } from '@mui/x-charts-premium/RadialBarChart';

const healthData = [
  { metric: 'Water', value: 5, goal: 8, color: '#00bcd4' },
  { metric: 'Sleep', value: 6.5, goal: 8, color: '#3f51b5' },
  { metric: 'Calories', value: 540, goal: 700, color: '#ff9800' },
  { metric: 'Activity', value: 42, goal: 60, color: '#4caf50' },
  { metric: 'Steps', value: 8200, goal: 10000, color: '#e91e63' },
];

const dataset = healthData.map((d) => ({
  metric: d.metric,
  progress: Math.round((d.value / d.goal) * 100),
}));

const highlightScope = { highlight: 'none', fade: 'none' } as const;

export default function HealthRadialBarChart() {
  return (
    <RadialBarChart
      height={400}
      dataset={dataset}
      series={[
        {
          dataKey: 'progress',
          layout: 'horizontal',
          label: 'Progress',
          highlightScope,
          valueFormatter: (value) => `${value}%`,
        },
      ]}
      radiusAxis={[
        {
          scaleType: 'band',
          dataKey: 'metric',
          categoryGapRatio: 0.3,
          disableLine: true,
          disableTicks: true,
          colorMap: {
            type: 'ordinal',
            values: healthData.map((d) => d.metric),
            colors: healthData.map((d) => d.color),
          },
        },
      ]}
      rotationAxis={[
        {
          scaleType: 'linear',
          disableTickLabel: true,
          disableLine: true,
          disableTicks: true,
          min: 0,
          max: 100,
          valueFormatter: (value) => `${value}%`,
        },
      ]}
      axisHighlight={{ rotation: 'none', radius: 'none' }}
      hideLegend
      slotProps={{ tooltip: { trigger: 'none' } }}
    />
  );
}

클릭 이벤트 (Click events)

RadialBarChart는 두 개의 클릭 핸들러를 제공합니다:

  • 특정 막대를 클릭할 때의 onItemClick
  • 차트 영역 어디든 클릭할 때의 onAxisClick

둘 다 다음 시그니처를 제공합니다:

const clickHandler = (
  event, // The mouse event.
  params, // An object that identifies the clicked elements.
) => {};
import * as React from 'react';
import Stack from '@mui/material/Stack';
import Box from '@mui/material/Box';
import Typography from '@mui/material/Typography';
import IconButton from '@mui/material/IconButton';
import UndoOutlinedIcon from '@mui/icons-material/UndoOutlined';
import {
  RadialBarChart,
  RadialBarSeries,
} from '@mui/x-charts-premium/RadialBarChart';
import { HighlightedCode } from '@mui/internal-core-docs/HighlightedCode';
import { ChartsAxisData } from '@mui/x-charts/models';
import { RadialBarItemIdentifier } from '@mui/x-charts-premium/models';
import ToggleButton from '@mui/material/ToggleButton';
import ToggleButtonGroup from '@mui/material/ToggleButtonGroup';

const highlightScope = { highlight: 'item' } as const;

const series: RadialBarSeries[] = [
  {
    id: 'series-1',
    data: [3, 4, 1, 6, 5],
    label: 'A',
    stack: 'total',
    highlightScope,
  },
  {
    id: 'series-2',
    data: [4, 3, 1, 5, 8],
    label: 'B',
    stack: 'total',
    highlightScope,
  },
  {
    id: 'series-3',
    data: [4, 2, 5, 4, 1],
    label: 'C',
    highlightScope,
  },
];

const bandAxis = {
  data: ['0', '3', '6', '9', '12'],
  id: 'axis1',
  scaleType: 'band' as const,
  disableLine: true,
  disableTicks: true,
};

const valueAxis = {
  tickLabelPosition: 'center' as const,
  disableLine: true,
  disableTicks: true,
};

const getRadialChartParams = (layout: 'vertical' | 'horizontal') => ({
  series: series.map((s) => ({ ...s, layout })),
  rotationAxis: [
    layout === 'vertical'
      ? bandAxis
      : { ...valueAxis, tickLabelPosition: 'after' as const },
  ],
  radiusAxis: [layout === 'vertical' ? valueAxis : bandAxis],
  grid: { rotation: true, radius: true },
  height: 400,
});

export default function RadialBarClick() {
  const [itemData, setItemData] = React.useState<RadialBarItemIdentifier>();
  const [axisData, setAxisData] = React.useState<ChartsAxisData | null>();
  const [layout, setLayout] = React.useState<'vertical' | 'horizontal'>('vertical');

  return (
    <Stack
      direction={{ xs: 'column', md: 'row' }}
      spacing={{ xs: 0, md: 4 }}
      sx={{ width: '100%' }}
    >
      <Box sx={{ flexGrow: 1 }}>
        <ToggleButtonGroup
          value={layout}
          exclusive
          onChange={(event, newLayout) => {
            if (newLayout !== null) {
              setLayout(newLayout);
            }
          }}
          aria-label="chart layout"
        >
          <ToggleButton key="vertical" value="vertical">
            vertical
          </ToggleButton>
          <ToggleButton key="horizontal" value="horizontal">
            horizontal
          </ToggleButton>
        </ToggleButtonGroup>
        <Box sx={{ flexGrow: 1 }}>
          <RadialBarChart
            {...getRadialChartParams(layout)}
            onItemClick={(event, d) => setItemData(d)}
            onAxisClick={(event, d) => setAxisData(d)}
          />
        </Box>
      </Box>

      <Stack direction="column" sx={{ width: { xs: '100%', md: '40%' } }}>
        <Box
          sx={{
            display: 'flex',
            justifyContent: 'space-between',
            alignItems: 'center',
          }}
        >
          <Typography>Click on the chart</Typography>
          <IconButton
            aria-label="reset"
            size="small"
            onClick={() => {
              setItemData(undefined);
              setAxisData(null);
            }}
          >
            <UndoOutlinedIcon fontSize="small" />
          </IconButton>
        </Box>
        <HighlightedCode
          code={`// Data from item click
${itemData ? JSON.stringify(itemData, null, 2) : '// The data will appear here'}

// Data from axis click
${axisData ? JSON.stringify(axisData, null, 2) : '// The data will appear here'}
`}
          language="json"
          copyButtonHidden
        />
      </Stack>
    </Stack>
  );
}

:::info onItemClick과 onAxisClick의 event 사이에는 약간의 차이가 있습니다:

  • onItemClick의 경우 이벤트는 차트 컨테이너가 발생시킨 React 합성 마우스 이벤트입니다. 방사형 막대에는 요소별 클릭 핸들러가 없으므로 클릭된 막대는 포인터 위치에서 해석됩니다.
  • onAxisClick의 경우 이벤트는 SVG 컴포넌트가 발생시킨 네이티브 마우스 이벤트입니다.

:::

사용자 지정 주석 및 오버레이 (Custom annotations and overlays)

참조선, 사용자 지정 마커, 데이터 오버레이 같은 고급 사용자 지정은 usePolarGeometry 훅을 사용하세요. 이 훅은 차트의 좌표 변환에 접근할 수 있게 해 주어 극좌표 공간 안에서 사용자 지정 SVG 요소를 정확히 배치할 수 있습니다.

일반적인 사용 사례는 다음과 같습니다:

  • 참조 링(Reference rings) — 시각적 목표 또는 임계값 표시기
  • 데이터 주석(Data annotations) — 특정 지점에 대한 라벨 및 마커
  • 기간 오버레이(Period overlays) — 현재 데이터를 과거 기간과 비교
  • 사용자 지정 마커(Custom markers) — 특정 좌표에 아이콘 또는 도형

자세한 예시와 API 참조는 usePolarGeometry 훅 문서를 참고하세요.

더 알아보기 (Learn more)