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

차트 - 피라미드 [<span class="plan-pro"></span>](/x/introduction/licensing/#pro-plan 'Pro plan')

원문 보기 위키 갱신

차트 - 피라미드

피라미드 차트는 깔때기(funnel) 차트의 변형입니다.

피라미드 차트

피라미드 차트를 만들려면 시리즈의 curve 속성을 pyramid로 설정하세요.

import Box from '@mui/material/Box';
import { FunnelChart } from '@mui/x-charts-pro/FunnelChart';

export default function Pyramid() {
  return (
    <Box sx={{ width: '100%', maxWidth: 400 }}>
      <FunnelChart
        series={[
          {
            curve: 'pyramid',
            data: [{ value: 10 }, { value: 100 }, { value: 1000 }, { value: 10000 }],
          },
        ]}
        height={300}
      />
    </Box>
  );
}

방향

피라미드는 제공된 데이터를 바탕으로 방향을 자동으로 바꿉니다. 값이 오름차순으로 정렬되어 있으면 피라미드는 똑바로(위로 향한) 그려집니다. 값이 내림차순으로 정렬되어 있으면 피라미드는 거꾸로(아래로 향한) 그려집니다.

피라미드의 방향을 직접 제어하려면 funnelDirection 속성을 increasing 또는 decreasing으로 설정할 수 있습니다.

이는 데이터가 정렬되어 있지 않을 때, 또는 데이터 순서와 무관하게 특정 방향을 강제하고 싶을 때 유용합니다.

import { FunnelChart } from '@mui/x-charts-pro/FunnelChart';
import ChartsUsageDemo from 'docs/src/modules/components/ChartsUsageDemo';
import Stack from '@mui/material/Stack';
import { populationByEducationLevelPercentageSeries } from '../funnel/populationByEducationLevel';

export default function PyramidDirection() {
  return (
    <ChartsUsageDemo
      componentName="Pyramid Chart"
      data={
        {
          direction: {
            displayName: 'Direction',
            knob: 'radio',
            options: ['auto', 'increasing', 'decreasing'],
            defaultValue: 'auto',
          },
        } as const
      }
      renderDemo={(props) => (
        <Stack sx={{ width: '100%' }}>
          <FunnelChart
            series={[
              {
                data: populationByEducationLevelPercentageSeries.data,
                curve: 'pyramid',
                funnelDirection: props.direction,
              },
            ]}
            height={300}
          />
        </Stack>
      )}
      getCode={({ props }) => {
        return `import { FunnelChart } from '@mui/x-charts-pro/FunnelChart';

<FunnelChart
  series={[{
    curve: 'pyramid',
    funnelDirection: '${props.direction}',
    ...
  }]}
/>
`;
      }}
    />
  );
}

세그먼트

기본적으로 피라미드 차트는 모든 세그먼트의 높이를 동일하게 만듭니다. 세그먼트를 값에 비례하게 만들려면 categoryAxis.scaleType을 linear로 설정하세요. 그러면 각 세그먼트의 높이가 나타내는 값에 따라 조정됩니다.

import Box from '@mui/material/Box';
import { FunnelChart } from '@mui/x-charts-pro/FunnelChart';

// datasource: https://ourworldindata.org/grapher/distribution-of-population-between-different-poverty-thresholds-stacke-bar-2011-ppp?country=~OWID_WRL&tableSearch=world

export default function PyramidSegmentLinear() {
  return (
    <Box sx={{ width: '100%', maxWidth: 400 }}>
      <FunnelChart
        series={[
          {
            curve: 'pyramid',
            data: [
              { label: 'Above $30 a day', value: 16 },
              { label: '$10-$30 a day', value: 25 },
              { label: '$1.90-$10 a day', value: 50 },
              { label: 'Below $1.90 a day', value: 9 },
            ],
            funnelDirection: 'increasing',
          },
        ]}
        categoryAxis={{ scaleType: 'linear' }}
        height={300}
      />
    </Box>
  );
}

스타일링

피라미드 차트는 깔때기 차트와 동일한 모든 방식으로 스타일링할 수 있습니다.

import { FunnelChart } from '@mui/x-charts-pro/FunnelChart';
import ChartsUsageDemo from 'docs/src/modules/components/ChartsUsageDemo';
import Stack from '@mui/material/Stack';
import { populationByEducationLevelPercentageSeries } from '../funnel/populationByEducationLevel';

const curveTypes = ['pyramid', 'step-pyramid'] as const;

export default function PyramidPlayground() {
  return (
    <ChartsUsageDemo
      componentName="Pyramid Chart"
      data={
        {
          direction: {
            knob: 'radio',
            options: ['vertical', 'horizontal'],
            defaultValue: 'vertical',
          },
          curveType: {
            knob: 'radio',
            options: curveTypes,
            defaultValue: curveTypes[0],
          },
          gap: {
            knob: 'slider',
            defaultValue: 0,
            min: 0,
            max: 20,
          },
          borderRadius: {
            knob: 'slider',
            defaultValue: 0,
            min: 0,
            max: 20,
          },
          variant: {
            knob: 'select',
            options: ['filled', 'outlined'],
            defaultValue: 'filled',
          },
        } as const
      }
      renderDemo={(props) => (
        <Stack sx={{ width: '100%' }}>
          <FunnelChart
            series={[
              {
                layout: props.direction,
                curve: props.curveType,
                variant: props.variant,
                borderRadius: props.borderRadius,
                data: [...populationByEducationLevelPercentageSeries.data].reverse(),
              },
            ]}
            gap={props.gap}
            height={300}
            slotProps={{ legend: { direction: 'vertical' } }}
          />
        </Stack>
      )}
      getCode={({ props }) => {
        return `import { FunnelChart } from '@mui/x-charts-pro/FunnelChart';

<FunnelChart
  series={[{ 
    layout: '${props.direction}',
    curve: '${props.curveType}',
    variant: '${props.variant}',
    borderRadius: ${props.borderRadius},
  }]}
  gap={${props.gap}}
/>
`;
      }}
    />
  );
}

더 알아보기 (Learn more)