BarChart
데이터 비교와 추이를 직관적으로 표현하는 바 차트 컴포넌트입니다. 세로/가로 레이아웃 전환, 그룹/누적 표시, 바 레이블 표시 등 다양한 표현 옵션을 제공합니다.
Playground
<Chart config={chartConfig} className="min-h-[200px]">
<BarChart accessibilityLayer data={chartData}>
<CartesianGrid vertical={false} />
<Chart.XAxis dataKey="month" tickLine={false} tickMargin={10} axisLine={false} />
<Chart.Tooltip content={<Chart.TooltipContent />} />
<Chart.Legend content={<Chart.LegendContent />} />
<Chart.Bar dataKey="desktop" fill="var(--color-desktop)" radius="base" />
<Chart.Bar dataKey="mobile" fill="var(--color-mobile)" radius="base" />
</BarChart>
</Chart>JSX Composition
Chart.*는 이 라이브러리에서, 그 외는 Recharts에서 import하세요.
<CartesianGrid /><Chart.YAxis /><Chart.Legend /><LabelList />Patterns
BarChart의 주요 표시 패턴입니다. 용도에 맞게 선택하세요.
Default
단일 시리즈 기본 바 차트
Multiple Bars
여러 시리즈를 나란히 배치해 비교
Stacked
여러 시리즈를 쌓아 합계 시각화
Horizontal
가로 방향 바 차트(layout="vertical")
Tooltip Styles
Chart.TooltipContent의 indicator prop으로 툴팁 인디케이터 모양을 변경할 수 있습니다.
Dot (default)
기본 도트 인디케이터
indicator="dot"Line
수직선 인디케이터
indicator="line"Dashed
점선 인디케이터
indicator="dashed"API
Component Structure
Chart— Recharts.BarProps바(radius, variant, layout, stackPosition).XAxisX축.YAxisY축.Tooltip툴팁 래퍼.TooltipContentProps툴팁 내용.Legend레전드 래퍼.LegendContent레전드 내용Props
Chart
config—ChartConfig차트 설정 객체(레이블 및 컬러 정의)
children—ReactElementRecharts 차트 컴포넌트
idundefinedstring차트의 고유 ID(CSS 변수 스코핑용)
hoverFadefalseboolean호버한 바 그룹을 풀 컬러로 표시하고 나머지는 페이드 아웃하는 하이라이트 효과를 활성화합니다
| Name | Type | Default | Description |
|---|---|---|---|
config | ChartConfig | — | 차트 설정 객체(레이블 및 컬러 정의) |
children | ReactElement | — | Recharts 차트 컴포넌트 |
id | string | undefined | 차트의 고유 ID(CSS 변수 스코핑용) |
hoverFade | boolean | false | 호버한 바 그룹을 풀 컬러로 표시하고 나머지는 페이드 아웃하는 하이라이트 효과를 활성화합니다 |
Chart.Bar
variant"solid""solid" | "outline"바 스타일. "outline"은 두꺼운 테두리와 반투명 채우기로 표시
radius"none""none" | "sm" | "base" | "md" | "lg"모서리 둥글기 크기. 디자인 토큰(--radius-*)에 대응한 이름 있는 variant
layout"vertical""vertical" | "horizontal"차트 방향. "horizontal"에서는 오른쪽(Y축 반대편)에 둥글기 적용
stackPosition"top""top" | "bottom"누적 바에서의 위치. "bottom"에서는 아래쪽 둥글기 적용
| Name | Type | Default | Description |
|---|---|---|---|
variant | "solid" | "outline" | "solid" | 바 스타일. "outline"은 두꺼운 테두리와 반투명 채우기로 표시 |
radius | "none" | "sm" | "base" | "md" | "lg" | "none" | 모서리 둥글기 크기. 디자인 토큰(--radius-*)에 대응한 이름 있는 variant |
layout | "vertical" | "horizontal" | "vertical" | 차트 방향. "horizontal"에서는 오른쪽(Y축 반대편)에 둥글기 적용 |
stackPosition | "top" | "bottom" | "top" | 누적 바에서의 위치. "bottom"에서는 아래쪽 둥글기 적용 |
Chart.TooltipContent
indicator"dot""dot" | "line" | "dashed"인디케이터 모양
hideLabelfalseboolean레이블 숨김
hideIndicatorfalseboolean인디케이터 숨김
colorundefinedstring인디케이터 컬러 직접 지정. 미지정 시 페이로드 컬러 사용
labelClassNameundefinedstring레이블 요소에 추가할 CSS 클래스
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 | 인디케이터 컬러 직접 지정. 미지정 시 페이로드 컬러 사용 |
labelClassName | string | undefined | 레이블 요소에 추가할 CSS 클래스 |
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"수직 위치(Recharts Legend에서 자동 주입)
align"center""left" | "center" | "right"수평 위치(Recharts Legend에서 자동 주입)
layout"horizontal""horizontal" | "vertical"레이아웃 방향(Recharts Legend에서 자동 주입)
| Name | Type | Default | Description |
|---|---|---|---|
hideIcon | boolean | false | 아이콘 숨김 |
nameKey | string | undefined | 데이터 키 이름 매핑 |
verticalAlign | "top" | "middle" | "bottom" | "bottom" | 수직 위치(Recharts Legend에서 자동 주입) |
align | "left" | "center" | "right" | "center" | 수평 위치(Recharts Legend에서 자동 주입) |
layout | "horizontal" | "vertical" | "horizontal" | 레이아웃 방향(Recharts Legend에서 자동 주입) |
Chart.XAxis / Chart.YAxis
tick{ style: { fontSize, fill } }object축 레이블 스타일. 기본적으로 디자인 토큰(--font-size-2xs, --color-text-subtle) 적용. 커스텀 객체로 덮어쓰기 가능
width (YAxis)"auto"number | "auto"Y축 너비. "auto"로 데이터에 맞게 자동 조정. 숫자로 고정 너비 지정 가능
...props—XAxisProps | YAxisPropsRecharts XAxis / YAxis의 모든 속성을 그대로 사용 가능
| Name | Type | Default | Description |
|---|---|---|---|
tick | object | { style: { fontSize, fill } } | 축 레이블 스타일. 기본적으로 디자인 토큰(--font-size-2xs, --color-text-subtle) 적용. 커스텀 객체로 덮어쓰기 가능 |
width (YAxis) | number | "auto" | "auto" | Y축 너비. "auto"로 데이터에 맞게 자동 조정. 숫자로 고정 너비 지정 가능 |
...props | XAxisProps | YAxisProps | — | Recharts XAxis / YAxis의 모든 속성을 그대로 사용 가능 |
Anatomy
Best Practices
권장
- ✓ChartConfig으로 레이블과 컬러를 일원 관리하세요
- ✓accessibilityLayer를 반드시 활성화하세요
- ✓min-h 또는 aspect-video로 컨테이너 크기를 지정하세요
- ✓디자인 토큰 컬러를 사용하세요
지양
- ✗하드코딩된 컬러 값을 직접 사용하지 마세요
- ✗컨테이너 크기 없이 차트를 배치하지 마세요
- ✗하나의 차트에 시리즈를 5개 이상 넣지 마세요
- ✗그리드 없이 데이터 비교를 강요하지 마세요
Accessibility
키보드 조작
ARIA / WCAG
accessibilityLayer키보드 및 스크린 리더 지원- Tooltip으로 데이터 값을 텍스트로 제공
- Legend로 시리즈 식별 가능
- 컬러 토큰으로 다크 모드 자동 대응