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 からインポートしてください。
<CartesianGrid /><Chart.YAxis /><Chart.Legend /><LabelList />Patterns
BarChartの主要な表示パターンです。用途に応じて使い分けてください。
Default
単一シリーズの基本的な棒グラフ
Multiple Bars
複数シリーズを並べて比較
Stacked
複数シリーズを積み上げて合計を視覚化
Horizontal
横方向の棒グラフ (layout="vertical")
Tooltip Styles
Chart.TooltipContentのindicatorpropで、ツールチップのインジケーター形状を変更できます。
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-*) に対応した名前付きバリアント
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-*) に対応した名前付きバリアント |
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シリーズ以上を1つのチャートに詰め込まない
- ✗グリッドなしでデータの比較を強制しない
Accessibility
キーボード操作
ARIA / WCAG
accessibilityLayerキーボード+SR対応- Tooltipでデータ値をテキストで提供
- Legendでシリーズを識別可能
- カラートークンでダークモード自動対応