PieChart
비율과 구성비를 직관적으로 표현하는 원형 차트 컴포넌트입니다. Pie와 Donut 두 가지 variant가 있으며, 라벨 위치와 중앙 텍스트를 자유롭게 커스터마이즈할 수 있습니다.
Playground
<Chart config={chartConfig} className="w-full mx-auto aspect-square max-h-[300px]">
<PieChart accessibilityLayer>
<Chart.Tooltip content={<Chart.TooltipContent hideLabel />} />
<Chart.Legend content={<Chart.LegendContent nameKey="key" />} />
<Chart.Pie data={chartData} dataKey="value" nameKey="name" />
</PieChart>
</Chart>JSX Composition
Chart.* Chart.*는 이 라이브러리에서, 나머지는 Recharts에서 import하세요.
<Chart.Legend />CSS 오버레이 (donut 전용)Patterns
PieChart의 주요 표시 패턴입니다. 용도에 맞게 선택하세요.
Default Pie
기본 원형 차트
Donut
도넛형 + 중앙 레이블
Outside Labels
외부 레이블 + 범례 포함
Styled Donut
패딩 + 둥근 모서리 도넛
Tooltip Styles
Chart.TooltipContent의 indicator prop으로 툴팁 인디케이터 형태를 변경할 수 있습니다.
Dot (default)
기본 점 인디케이터
indicator="dot"Line
수직선 인디케이터
indicator="line"Dashed
파선 인디케이터
indicator="dashed"API
Component Structure
Chart— Recharts.PieProps파이(variant, label, activeShape).Tooltip툴팁 래퍼.TooltipContentProps툴팁 내용.Legend범례 래퍼.LegendContent범례 내용Props
Chart
config—ChartConfig차트 설정 객체(레이블 및 색상 정의)
children—ReactElementRecharts 차트 컴포넌트
idundefinedstring차트의 고유 ID(CSS 변수 스코핑용)
| Name | Type | Default | Description |
|---|---|---|---|
config | ChartConfig | — | 차트 설정 객체(레이블 및 색상 정의) |
children | ReactElement | — | Recharts 차트 컴포넌트 |
id | string | undefined | 차트의 고유 ID(CSS 변수 스코핑용) |
Chart.Pie
variant"pie""pie" | "donut"형태. "donut"은 innerRadius를 자동 설정
label"none""none" | "outside" | "inside"레이블 위치. outside=콜아웃 선, inside=슬라이스 내부(작은 슬라이스는 자동 숨김)
labelContent"value""value" | "percent"레이블에 표시할 내용
activeShapetrueboolean호버 시 슬라이스를 확대하는 효과
innerRadius0 (pie) / 60 (donut)number내부 반지름. variant로 자동 설정되지만 직접 덮어쓰기 가능
paddingAngle0number슬라이스 간 간격(도)
cornerRadius0number슬라이스 모서리 둥글기
startAngle90number시작 각도(90 = 12시 방향)
endAngle-270number끝 각도
| Name | Type | Default | Description |
|---|---|---|---|
variant | "pie" | "donut" | "pie" | 형태. "donut"은 innerRadius를 자동 설정 |
label | "none" | "outside" | "inside" | "none" | 레이블 위치. outside=콜아웃 선, inside=슬라이스 내부(작은 슬라이스는 자동 숨김) |
labelContent | "value" | "percent" | "value" | 레이블에 표시할 내용 |
activeShape | boolean | true | 호버 시 슬라이스를 확대하는 효과 |
innerRadius | number | 0 (pie) / 60 (donut) | 내부 반지름. variant로 자동 설정되지만 직접 덮어쓰기 가능 |
paddingAngle | number | 0 | 슬라이스 간 간격(도) |
cornerRadius | number | 0 | 슬라이스 모서리 둥글기 |
startAngle | number | 90 | 시작 각도(90 = 12시 방향) |
endAngle | number | -270 | 끝 각도 |
Chart.TooltipContent
indicator"dot""dot" | "line" | "dashed"인디케이터 형태
hideLabelfalseboolean레이블 숨기기
hideIndicatorfalseboolean인디케이터 숨기기
colorundefinedstring인디케이터 색상 직접 지정
nameKeyundefinedstring데이터 키의 이름 매핑
labelKeyundefinedstring레이블 키 매핑
labelFormatterundefined(value, payload) => ReactNode레이블 커스텀 포매터
formatterundefined(value, name, item, index, payload) => ReactNode값 커스텀 포매터
| Name | Type | Default | Description |
|---|---|---|---|
indicator | "dot" | "line" | "dashed" | "dot" | 인디케이터 형태 |
hideLabel | boolean | false | 레이블 숨기기 |
hideIndicator | boolean | false | 인디케이터 숨기기 |
color | string | undefined | 인디케이터 색상 직접 지정 |
nameKey | string | undefined | 데이터 키의 이름 매핑 |
labelKey | string | undefined | 레이블 키 매핑 |
labelFormatter | (value, payload) => ReactNode | undefined | 레이블 커스텀 포매터 |
formatter | (value, name, item, index, payload) => ReactNode | undefined | 값 커스텀 포매터 |
Chart.LegendContent
hideIconfalseboolean아이콘 숨기기
nameKeyundefinedstring데이터 키의 이름 매핑
verticalAlign"bottom""top" | "middle" | "bottom"수직 위치
align"center""left" | "center" | "right"수평 위치
layout"horizontal""horizontal" | "vertical"레이아웃 방향
| Name | Type | Default | Description |
|---|---|---|---|
hideIcon | boolean | false | 아이콘 숨기기 |
nameKey | string | undefined | 데이터 키의 이름 매핑 |
verticalAlign | "top" | "middle" | "bottom" | "bottom" | 수직 위치 |
align | "left" | "center" | "right" | "center" | 수평 위치 |
layout | "horizontal" | "vertical" | "horizontal" | 레이아웃 방향 |
Customization
도넛형의 중앙 레이블은 CSS 오버레이로 구현하므로 HTML 콘텐츠를 자유롭게 커스터마이즈할 수 있습니다.
숫자 + 레이블
<div className="absolute inset-0 flex flex-col items-center justify-center pointer-events-none">
<span className="text-3xl font-bold">925</span>
<span className="text-sm text-text-muted">Total</span>
</div>아이콘 + 퍼센트
<div className="absolute inset-0 flex flex-col items-center justify-center pointer-events-none">
<TrendingUp className="icon-md text-success" />
<span className="text-lg font-bold">+12%</span>
<span className="text-xs text-text-muted">Growth</span>
</div>리치 콘텐츠
<div className="absolute inset-0 flex flex-col items-center justify-center pointer-events-none">
<span className="text-xs text-text-muted">Revenue</span>
<span className="text-2xl font-bold">$4.2k</span>
<span className="text-xs font-semibold text-success">+8.5%</span>
</div>Tip:중앙 레이블은 CSS 오버레이(absolute + pointer-events-none)로 구현하므로 텍스트, 아이콘, 커스텀 컴포넌트 등 모든 HTML 콘텐츠를 자유롭게 배치할 수 있습니다.
Anatomy
Best Practices
권장
- ✓슬라이스 수는 5~6개 이내로 유지
- ✓도넛형으로 중앙에 합계값이나 KPI를 표시
- ✓Tooltip으로 정확한 수치를 제공
- ✓Legend로 각 슬라이스를 식별 가능하게
- ✓accessibilityLayer를 반드시 활성화
지양
- ✗슬라이스 7개 이상은 사용하지 않기(BarChart가 더 적합)
- ✗유사한 값이 많은 경우 지양(차이가 보이지 않음)
- ✗시계열 데이터에는 사용하지 않기(LineChart 권장)
- ✗색상만으로 구분하지 않기(Legend나 레이블 병용)
Accessibility
키보드 조작
ARIA / WCAG
- Tooltip으로 데이터 값을 텍스트로 제공
- Legend로 슬라이스를 식별 가능
- 컬러 토큰으로 다크 모드 자동 대응
- activeShape으로 호버 피드백 제공
accessibilityLayer키보드 및 SR 지원 활성화