차트 - 깔때기
차트 - 깔때기 (Funnel)
깔때기 차트로 전환(conversion)이나 참여(engagement) 단계처럼 순차적인 단계를 거치며 수량이 어떻게 변화하는지 보여줄 수 있어요.
본문
개요 (Overview)
깔때기 차트는 순차적인 단계를 거치며 수량이 좁아지거나 커지는 모습을 보여줘요. 대상자 참여(audience engagement), 교육 수준, 전환 파이프라인 같은 흐름에 사용하면 좋습니다.
아래 데모는 감소하는 값 4개를 가진 간단한 깔때기를 보여줘요.
import Box from '@mui/material/Box';
import { FunnelChart } from '@mui/x-charts-pro/FunnelChart';
export default function BasicFunnel() {
return (
<Box sx={{ width: '100%', maxWidth: 400 }}>
<FunnelChart
series={[
{
data: [{ value: 200 }, { value: 180 }, { value: 90 }, { value: 50 }],
},
]}
height={300}
/>
</Box>
);
}
기본 (Basics)
깔때기 차트 시리즈는 객체 배열인 data 속성을 반드시 포함해야 해요. 각 객체가 하나의 섹션이며 value 속성을 가져야 합니다. label이나 id 같은 선택 속성도 추가할 수 있어요.
범례 (Legend)
깔때기는 기본적으로 범례를 표시합니다. 범례 텍스트를 보여주려면 각 데이터 객체에 label을 제공하세요.
범례를 숨기려면 hideLegend를 true로 설정하세요.
import * as React from 'react';
import Box from '@mui/material/Box';
import { FunnelChart } from '@mui/x-charts-pro/FunnelChart';
import FormControlLabel from '@mui/material/FormControlLabel';
import Checkbox from '@mui/material/Checkbox';
export default function FunnelLegend() {
const [hideLegend, setHideLegend] = React.useState(false);
return (
<Box sx={{ width: '100%', maxWidth: 400 }}>
<Controls hideLegend={hideLegend} setHideLegend={setHideLegend} />
<FunnelChart
series={[
{
data: [
{ value: 200, label: 'A' },
{ value: 180, label: 'B' },
{ value: 90, label: 'C' },
{ value: 50, label: 'D' },
],
},
]}
hideLegend={hideLegend}
{...funnelProps}
/>
</Box>
);
}
const funnelProps = {
height: 300,
slotProps: { legend: { position: { vertical: 'bottom' } } },
} as const;
function Controls({
hideLegend,
setHideLegend,
}: {
hideLegend: boolean;
setHideLegend: React.Dispatch<React.SetStateAction<boolean>>;
}) {
return (
<FormControlLabel
control={
<Checkbox
checked={hideLegend}
onChange={() => setHideLegend((prev) => !prev)}
/>
}
label="Hide legend"
/>
);
}
피라미드 차트 (Pyramid chart)
피라미드 차트는 위아래가 뒤집힌(역전된) 모양의 깔때기예요.
시리즈에 curve 속성을 'pyramid'로 설정하세요.
import Box from '@mui/material/Box';
import { FunnelChart } from '@mui/x-charts-pro/FunnelChart';
export default function PyramidFunnel() {
return (
<Box sx={{ width: '100%', maxWidth: 400 }}>
<FunnelChart
series={[
{
curve: 'pyramid',
data: [{ value: 10 }, { value: 90 }, { value: 180 }, { value: 400 }],
},
]}
height={300}
/>
</Box>
);
}
라벨 (Labels)
깔때기는 기본적으로 라벨(각 섹션의 value)을 표시해요. 이를 포맷하려면 valueFormatter prop을 사용하세요.
import Box from '@mui/material/Box';
import { FunnelChart } from '@mui/x-charts-pro/FunnelChart';
export default function FunnelLabels() {
return (
<Box sx={{ width: '100%', maxWidth: 400 }}>
<FunnelChart
series={[
{
data: [
{ value: 200, label: 'A' },
{ value: 180, label: 'B' },
{ value: 90, label: 'C' },
{ value: 50, label: 'D' },
],
valueFormatter: (item, context) =>
`${item.label}${context.dataIndex} ${item.value}.00`,
},
]}
{...funnelProps}
/>
</Box>
);
}
const funnelProps = {
height: 300,
hideLegend: true,
} as const;
라벨 스타일링 (Styling labels)
라벨을 스타일링하려면 funnelSectionClasses.label 클래스를 사용하세요.
import Box from '@mui/material/Box';
import { FunnelChart, funnelClasses } from '@mui/x-charts-pro/FunnelChart';
export default function FunnelLabelStyling() {
return (
<Box sx={{ width: '100%', maxWidth: 400 }}>
<FunnelChart
series={[
{
data: [{ value: 200 }, { value: 180 }, { value: 90 }, { value: 50 }],
},
]}
sx={{
[`& .${funnelClasses.sectionLabel}`]: {
fill: 'white',
textShadow: '1px 1px 2px rgba(0,0,0,0.5)',
},
}}
{...funnelProps}
/>
</Box>
);
}
const funnelProps = {
height: 300,
hideLegend: true,
} as const;
라벨 위치 지정 (Positioning labels)
sectionLabel 속성은 라벨 위치를 제어해요. 다음을 포함하는 객체를 받습니다.
position.vertical:'top','middle', 또는'bottom'position.horizontal:'start','center', 또는'end'offset: 라벨과 섹션 앵커 사이의 공간. 두 축 모두에 숫자를 전달하거나{ x?, y? }를 전달하세요.
textAnchor와 dominantBaseline은 SVG text 요소로 전달됩니다. 이들은 CSS 속성이 아니라 같은 이름의 SVG 속성처럼 동작하며, 깔때기 차트는 아래 값만 허용해요. 각 키워드가 무엇을 하는지는 MDN의 text-anchor와 dominant-baseline을 참고하세요.
textAnchor:'start','middle', 또는'end'dominantBaseline:'auto','baseline','hanging','middle','central','text-after-edge', 또는'text-before-edge'
라벨을 숨기려면 sectionLabel을 false로 설정하세요. 데이터 객체를 받아 라벨 설정을 반환하는 함수를 전달할 수도 있어요.
import { FunnelChart } from '@mui/x-charts-pro/FunnelChart';
import ChartsUsageDemo from 'docs/src/modules/components/ChartsUsageDemo';
import Stack from '@mui/material/Stack';
export default function FunnelLabelPositioning() {
return (
<ChartsUsageDemo
componentName="Funnel label positioning"
data={
{
horizontal: {
knob: 'select',
defaultValue: 'start',
options: ['start', 'center', 'end'],
},
vertical: {
knob: 'select',
defaultValue: 'bottom',
options: ['top', 'middle', 'bottom'],
},
textAnchor: {
knob: 'select',
defaultValue: 'start',
options: ['start', 'middle', 'end'],
},
dominantBaseline: {
knob: 'select',
defaultValue: 'middle',
options: [
'auto',
'hanging',
'middle',
'central',
'text-after-edge',
'text-before-edge',
],
},
offsetX: {
knob: 'slider',
defaultValue: -10,
min: -50,
max: 50,
},
offsetY: {
knob: 'slider',
defaultValue: 10,
min: -50,
max: 50,
},
hide: {
knob: 'switch',
},
} as const
}
renderDemo={(props) => (
<Stack sx={{ width: '100%' }}>
<FunnelChart
series={[
{
layout: 'vertical',
data: [
{ value: 200, label: 'A' },
{ value: 180, label: 'B' },
{ value: 90, label: 'C' },
{ value: 50, label: 'D' },
],
sectionLabel: props.hide
? false
: {
position: {
horizontal: props.horizontal,
vertical: props.vertical,
},
textAnchor: props.textAnchor,
dominantBaseline: props.dominantBaseline,
offset: {
x: props.offsetX,
y: props.offsetY,
},
},
},
]}
height={300}
slotProps={{ legend: { direction: 'vertical' } }}
/>
</Stack>
)}
getCode={({ props }) => {
if (props.hide) {
return `import { FunnelChart } from '@mui/x-charts-pro/FunnelChart';
<FunnelChart
series={[
{
sectionLabel: false
}
]}
/>
`;
}
return `import { FunnelChart } from '@mui/x-charts-pro/FunnelChart';
<FunnelChart
// Space to display the labels
series={[
{
sectionLabel: {
position: {
horizontal: '${props.horizontal}',
vertical: '${props.vertical}'
},
textAnchor: '${props.textAnchor}',
dominantBaseline: '${props.dominantBaseline}',
offset: {
x: ${props.offsetX},
y: ${props.offsetY}
}
}
}
]}
/>
`;
}}
/>
);
}
스타일링 (Styling)
커브 보간 (Curve interpolation)
curve 속성으로 섹션 사이의 모양을 선택할 수 있어요. 'linear', 'linear-sharp', 'bump', 'pyramid', 'step', 또는 'step-pyramid'를 받습니다.
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 './populationByEducationLevel';
const curveTypes = [
'bump',
'linear',
'linear-sharp',
'step',
'pyramid',
'step-pyramid',
] as const;
export default function FunnelCurves() {
return (
<ChartsUsageDemo
componentName="Funnel curve"
data={
{
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={[
{
curve: props.curveType,
borderRadius: props.borderRadius,
layout: 'vertical',
variant: props.variant,
funnelDirection: 'increasing',
...populationByEducationLevelPercentageSeries,
},
]}
gap={props.gap}
height={300}
slotProps={{ legend: { direction: 'vertical' } }}
/>
<FunnelChart
series={[
{
curve: props.curveType,
borderRadius: props.borderRadius,
layout: 'horizontal',
variant: props.variant,
funnelDirection: 'increasing',
...populationByEducationLevelPercentageSeries,
},
]}
gap={props.gap}
height={300}
slotProps={{ legend: { direction: 'vertical' } }}
/>
</Stack>
)}
getCode={({ props }) => {
return `import { FunnelChart } from '@mui/x-charts-pro/FunnelChart';
<FunnelChart
series={[{
curve: '${props.curveType}',
variant: '${props.variant}',
${props.curveType === 'bump' ? '// ' : ''}borderRadius: ${props.borderRadius},
}]}
gap={${props.gap}}
/>
`;
}}
/>
);
}
간격 (Gap)
gap 속성으로 섹션 사이의 공간(픽셀 단위)을 설정할 수 있어요.
import Box from '@mui/material/Box';
import { FunnelChart } from '@mui/x-charts-pro/FunnelChart';
export default function FunnelGap() {
return (
<Box sx={{ width: '100%', maxWidth: 400 }}>
<FunnelChart
series={[
{
data: [{ value: 200 }, { value: 180 }, { value: 90 }, { value: 50 }],
},
]}
height={300}
gap={10}
/>
</Box>
);
}
테두리 반경 (Border radius)
borderRadius 속성으로 섹션 모서리를 둥글게 만들 수 있어요(픽셀 단위).
bump 커브는 테두리 반경을 무시합니다. linear, linear-sharp, pyramid 커브는 섹션 각도에 따라 일부만 적용되며, step과 step-pyramid 커브는 완전히 적용됩니다.
curve와 borderRadius가 어떻게 상호작용하는지는 Curve interpolation을 참고하세요.
gap이 0이면 반경은 다른 섹션과 연결되지 않은 모서리에만 적용되고, gap이 0보다 크면 모든 모서리에 적용됩니다.
import Box from '@mui/material/Box';
import { FunnelChart } from '@mui/x-charts-pro/FunnelChart';
export default function FunnelBorderRadius() {
return (
<Box sx={{ width: '100%', maxWidth: 400 }}>
<FunnelChart
series={[
{
data: [{ value: 200 }, { value: 180 }, { value: 90 }, { value: 50 }],
borderRadius: 10,
},
]}
height={300}
/>
<FunnelChart
series={[
{
data: [{ value: 200 }, { value: 180 }, { value: 90 }, { value: 50 }],
borderRadius: 10,
},
]}
height={300}
gap={10}
/>
</Box>
);
}
변형 (Variant)
variant 속성으로 스타일을 전환할 수 있어요.
'filled'(기본값): 단색 채움, 스트로크 없음'outlined': 색상 스트로크가 있는 반투명 채움
outlined 변형은 시각적으로 더 가볍습니다.
import Box from '@mui/material/Box';
import { FunnelChart } from '@mui/x-charts-pro/FunnelChart';
export default function FunnelVariant() {
const data = [
{ value: 200, label: 'Leads' },
{ value: 150, label: 'Calls' },
{ value: 90, label: 'Meetings' },
{ value: 40, label: 'Deals' },
];
return (
<Box sx={{ width: '100%', maxWidth: 400 }}>
<FunnelChart
series={[
{
data,
variant: 'outlined',
},
]}
height={300}
/>
</Box>
);
}
색상 (Colors)
깔때기 색상은 두 가지 방법으로 커스터마이즈할 수 있어요.
- 색상 팔레트를 전달하세요. 각 섹션은 팔레트에서 색상을 하나씩 사용합니다.
- 각 데이터 객체에
color속성을 설정하면 해당 섹션의 팔레트 색상을 덮어씁니다.
import Box from '@mui/material/Box';
import { FunnelChart } from '@mui/x-charts-pro/FunnelChart';
export default function FunnelColor() {
return (
<Box sx={{ width: '100%', maxWidth: 400 }}>
<FunnelChart
colors={['hotpink', 'red']} // Use custom colors
series={[
{
data: [
{ value: 20 }, // Get color from the palette
{ value: 10, color: 'slateblue' }, // Override palette color (red)
{ value: 5 },
],
},
]}
height={300}
/>
</Box>
);
}
CSS
깔때기를 CSS로 스타일링할 수 있어요. 각 섹션 그룹에는 타겟팅을 위한 data-series 속성이 있습니다. 아래 데모처럼 :nth-child 또는 :nth-of-type을 사용해 특정 섹션을 타겟팅할 수 있어요.
import Box from '@mui/material/Box';
import { FunnelChart, funnelClasses } from '@mui/x-charts-pro/FunnelChart';
export default function FunnelDataAttributes() {
return (
<Box sx={{ width: '100%', maxWidth: 400 }}>
<FunnelChart
{...funnelProps}
sx={{
[`[data-series="main"] .${funnelClasses.section}:nth-of-type(1)`]: {
fill: 'url(#pattern)',
},
}}
>
<defs>
<pattern id="pattern" width="50" height="50" patternUnits="userSpaceOnUse">
<rect width="100%" height="100%" fill="hotpink" />
<circle fill="slateblue" cx="15" cy="15" r="10" />
<circle fill="slateblue" cx="40" cy="40" r="10" />
</pattern>
</defs>
</FunnelChart>
</Box>
);
}
const funnelProps = {
height: 300,
hideLegend: true,
series: [
{
id: 'main',
data: [{ value: 200 }, { value: 180 }, { value: 90 }, { value: 50 }],
},
],
} as const;
여러 개의 깔때기 (Multiple funnels)
기본적으로 여러 시리즈는 쌓입니다(stacked). 시리즈를 여러 개 전달하고 서로 다른 색상이나 스타일로 구분하세요. 첫 번째 시리즈가 맨 아래, 마지막 시리즈가 맨 위에 위치합니다.
import Box from '@mui/material/Box';
import { FunnelChart, FunnelChartProps } from '@mui/x-charts-pro/FunnelChart';
export default function FunnelStacked() {
return (
<Box sx={{ width: '100%', maxWidth: 500 }}>
<FunnelChart
sx={{ '& [data-series="big"]': { filter: 'brightness(0.7)' } }}
series={[
{
id: 'big',
data: dataBig,
sectionLabel: {
position: { horizontal: 'end' },
textAnchor: 'start',
offset: { x: 10 },
},
},
{ data: dataSmall, curve: 'bump' },
]}
height={300}
/>
</Box>
);
}
const dataBig: FunnelChartProps['series'][any]['data'] = [
{ value: 500, label: 'A1' },
{ value: 280, label: 'B1' },
{ value: 190, label: 'C1' },
{ value: 70, label: 'D1' },
];
const dataSmall: FunnelChartProps['series'][any]['data'] = [
{ value: 200, label: 'A2' },
{ value: 180, label: 'B2' },
{ value: 90, label: 'C2' },
{ value: 50, label: 'D2' },
];
하이라이트 (Highlight)
highlightScope.highlight을 'item'으로 설정하면 호버된 섹션을 강조해요. highlightScope.fade를 'global'로 설정하면 다른 섹션을 흐리게 합니다.
import * as React from 'react';
import Stack from '@mui/material/Stack';
import TextField from '@mui/material/TextField';
import MenuItem from '@mui/material/MenuItem';
import { FunnelChart } from '@mui/x-charts-pro/FunnelChart';
import { FadeOptions, HighlightOptions } from '@mui/x-charts/context';
import { populationByEducationLevelPercentageSeriesLabeled } from './populationByEducationLevel';
export default function HighlightFunnel() {
const [highlight, setHighlight] = React.useState<HighlightOptions>('item');
const [fade, setFade] = React.useState<FadeOptions>('global');
return (
<Stack spacing={1} sx={{ width: '100%' }}>
<Stack spacing={1} direction={{ xs: 'column', sm: 'row' }}>
<FunnelChart
series={[
{
...populationByEducationLevelPercentageSeriesLabeled,
highlightScope: {
highlight,
fade,
},
},
]}
{...funnelChartParams}
/>
<FunnelChart
series={[
{
...populationByEducationLevelPercentageSeriesLabeled,
variant: 'outlined',
highlightScope: {
highlight,
fade,
},
},
]}
{...funnelChartParams}
/>
</Stack>
<Controls
highlight={highlight}
setHighlight={setHighlight}
fade={fade}
setFade={setFade}
/>
</Stack>
);
}
const funnelChartParams = {
height: 300,
hideLegend: true,
};
function Controls({
highlight,
setHighlight,
fade,
setFade,
}: {
highlight: string;
setHighlight: React.Dispatch<React.SetStateAction<HighlightOptions>>;
fade: string;
setFade: React.Dispatch<React.SetStateAction<FadeOptions>>;
}) {
return (
<Stack
direction={{ xs: 'row', xl: 'column' }}
spacing={3}
useFlexGap
sx={{ justifyContent: 'center', flexWrap: 'wrap' }}
>
<TextField
select
label="highlight"
value={highlight}
onChange={(event) => setHighlight(event.target.value as HighlightOptions)}
sx={{ minWidth: 150 }}
>
<MenuItem value={'none'}>none</MenuItem>
<MenuItem value={'item'}>item</MenuItem>
<MenuItem value={'series'}>series</MenuItem>
</TextField>
<TextField
select
label="fade"
value={fade}
onChange={(event) => setFade(event.target.value as FadeOptions)}
sx={{ minWidth: 150 }}
>
<MenuItem value={'none'}>none</MenuItem>
<MenuItem value={'series'}>series</MenuItem>
<MenuItem value={'global'}>global</MenuItem>
</TextField>
</Stack>
);
}
카테고리 축 (Category axis)
깔때기는 차트 방향을 따르는 카테고리 축을 사용해요. 기본적으로 축은 숨겨져 있습니다.
표시하려면 categoryAxis prop에 position과 categories를 전달하세요.
import Box from '@mui/material/Box';
import { FunnelChart } from '@mui/x-charts-pro/FunnelChart';
import { populationByEducationLevelPercentageSeriesLabeled } from './populationByEducationLevel';
export default function FunnelCategoryAxis() {
return (
<Box sx={{ width: '100%', maxWidth: 400 }}>
<FunnelChart
series={[populationByEducationLevelPercentageSeriesLabeled]}
categoryAxis={{
categories: ['First', 'Second', 'Third', 'Fourth', 'Fifth'],
position: 'left',
disableLine: true,
disableTicks: true,
size: 60,
}}
{...funnelProps}
/>
</Box>
);
}
const funnelProps = {
height: 300,
hideLegend: true,
} as const;
크기가 조정된 섹션 (Scaled sections)
기본적으로 섹션은 band 스케일(동일한 너비)을 사용합니다. categoryAxis 설정에서 scaleType을 'linear'로 설정하면 섹션 너비를 값에 따라 조정할 수 있어요.
import Box from '@mui/material/Box';
import { FunnelChart } from '@mui/x-charts-pro/FunnelChart';
import { populationByEducationLevelPercentageSeriesLabeled } from './populationByEducationLevel';
export default function FunnelLinearScale() {
return (
<Box sx={{ width: '100%', maxWidth: 400 }}>
<FunnelChart
series={[populationByEducationLevelPercentageSeriesLabeled]}
categoryAxis={{ scaleType: 'linear' }}
{...funnelProps}
/>
</Box>
);
}
const funnelProps = {
height: 300,
hideLegend: true,
} as const;
자동 크기 조정 축 (Auto-sizing axis)
축 size를 'auto'로 설정하면 눈금 라벨의 측정값을 기반으로 축 크기를 자동 계산할 수 있어요. 눈금 라벨의 길이가 제각각일 때 유용합니다.
import * as React from 'react';
import Box from '@mui/material/Box';
import Stack from '@mui/material/Stack';
import FormControlLabel from '@mui/material/FormControlLabel';
import Checkbox from '@mui/material/Checkbox';
import { FunnelChart } from '@mui/x-charts-pro/FunnelChart';
export default function FunnelAxisAutoSize() {
const [useAutoSize, setUseAutoSize] = React.useState(true);
return (
<Box sx={{ width: '100%' }}>
<Stack direction="row" spacing={1} sx={{ mb: 2 }}>
<FormControlLabel
checked={useAutoSize}
control={
<Checkbox onChange={(event) => setUseAutoSize(event.target.checked)} />
}
label="Use auto-sizing"
labelPlacement="end"
/>
</Stack>
<FunnelChart
series={[funnelSeries]}
categoryAxis={{
categories,
position: 'left',
disableLine: true,
disableTicks: true,
size: useAutoSize ? 'auto' : undefined,
}}
height={300}
hideLegend
/>
</Box>
);
}
const categories = [
'Website visitors',
'Product page views',
'Added to cart',
'Checkout started',
'Purchase completed',
];
const funnelSeries = {
data: [
{ value: 10000, label: 'Website visitors' },
{ value: 7500, label: 'Product page views' },
{ value: 3200, label: 'Added to cart' },
{ value: 1800, label: 'Checkout started' },
{ value: 950, label: 'Purchase completed' },
],
};