バブルチャートライブラリ比較
3変数(X軸・Y軸・バブルサイズ)を同時に可視化し、散布図を拡張したバブルチャートの実装を5つのライブラリで比較
1. Recharts
ScatterChart + ZAxisの組み合わせで第3変数をバブルサイズに直感的にマッピング
'use client';
import {
ScatterChart, Scatter, XAxis, YAxis, ZAxis,
CartesianGrid, Tooltip, Legend, ResponsiveContainer,
} from 'recharts';
const divisionA = [
{ sales: 1200, profit: 18, share: 15 },
{ sales: 850, profit: 12, share: 8 },
{ sales: 2100, profit: 25, share: 22 },
{ sales: 450, profit: 8, share: 4 },
];
const divisionB = [
{ sales: 1680, profit: 20, share: 17 },
{ sales: 950, profit: 15, share: 10 },
{ sales: 720, profit: 6, share: 6 },
{ sales: 3200, profit: 30, share: 28 },
];
export function RechartsBubbleChart() {
return (
<ResponsiveContainer width="100%" height={300}>
<ScatterChart>
<CartesianGrid strokeDasharray="3 3" />
<XAxis type="number" dataKey="sales" name="売上高" unit="万円"
label={{ value: '売上高(万円)', position: 'insideBottom', offset: -5, fontSize: 11 }} />
<YAxis type="number" dataKey="profit" name="利益率" unit="%"
label={{ value: '利益率(%)', angle: -90, position: 'insideLeft', fontSize: 11 }} />
<ZAxis type="number" dataKey="share" name="市場シェア" unit="%" range={[50, 1000]} />
<Tooltip cursor={{ strokeDasharray: '3 3' }} />
<Legend verticalAlign="top" />
<Scatter name="事業部A" data={divisionA} fill="#3b82f6" fillOpacity={0.6} />
<Scatter name="事業部B" data={divisionB} fill="#10b981" fillOpacity={0.6} />
</ScatterChart>
</ResponsiveContainer>
);
}🤖 AIプロンプトテンプレート
React + Tailwind CSSで、Rechartsを使ったバブルチャートを実装してください。 - 使用ライブラリ: recharts(ScatterChart、Scatter、XAxis、YAxis、ZAxis、CartesianGrid、Tooltip、Legend、ResponsiveContainer) - サンプルデータ: 2事業部の売上高・利益率・市場シェア(各4件)を用意すること - 第3変数: ZAxisのdataKeyで市場シェアをバブルサイズにマッピングすること(range=[50, 1000]) - インタラクティブ: ホバー時にツールチップで3変数の値(単位付き)を表示すること - グループ区別: Scatterコンポーネントを複数配置し、fillカラーで事業部ごとに色分けして表示すること - レスポンシブ: ResponsiveContainerで親要素の幅に応じてチャートサイズが変わるよう対応すること - 透明度: fillOpacityを0.6に設定してバブルの重なりを見やすくすること
⚠️ このプロンプトはあくまでたたき台です。AIの回答はモデルやバージョン、会話の文脈によって毎回異なります。意図通りに動かない場合は、条件を追記・修正してお使いください。
2. Nivo
ResponsiveScatterPlotのnodeSizeに関数を渡して市場シェアを動的にバブルサイズへ変換
'use client';
import { ResponsiveScatterPlot } from '@nivo/scatterplot';
const data = [
{
id: '事業部A',
data: [
{ x: 1200, y: 18, share: 15 },
{ x: 850, y: 12, share: 8 },
{ x: 2100, y: 25, share: 22 },
{ x: 450, y: 8, share: 4 },
],
},
{
id: '事業部B',
data: [
{ x: 1680, y: 20, share: 17 },
{ x: 950, y: 15, share: 10 },
{ x: 720, y: 6, share: 6 },
{ x: 3200, y: 30, share: 28 },
],
},
];
export function NivoBubbleChart() {
return (
<div style={{ height: 300 }}>
<ResponsiveScatterPlot
data={data}
margin={{ top: 20, right: 120, bottom: 60, left: 70 }}
xScale={{ type: 'linear', min: 0, max: 'auto' }}
yScale={{ type: 'linear', min: 0, max: 'auto' }}
nodeSize={(datum: any) => datum.data.share * 1.5 + 5}
axisBottom={{ legend: '売上高(万円)', legendPosition: 'middle', legendOffset: 46 }}
axisLeft={{ legend: '利益率(%)', legendPosition: 'middle', legendOffset: -56 }}
colors={['#3b82f6', '#10b981']}
useMesh={false}
legends={[{ anchor: 'bottom-right', direction: 'column', itemWidth: 80, itemHeight: 20 }]}
/>
</div>
);
}🤖 AIプロンプトテンプレート
React + Tailwind CSSで、Nivoを使ったバブルチャートを実装してください。
- 使用ライブラリ: @nivo/scatterplot(ResponsiveScatterPlot)
- サンプルデータ: 2事業部の売上高・利益率・市場シェア(各4件)をNivo形式({id, data: [{x, y, share}]})で用意すること
- 第3変数: nodeSizeプロパティに関数を設定し、市場シェアをバブルサイズに動的マッピングすること(例: (datum) => datum.data.share * 1.5 + 5)
- インタラクティブ: ホバー時にツールチップで3変数の値を表示すること(useMesh: true)
- グループ区別: colorsプロパティで事業部ごとに色分けし、凡例を表示すること
- 軸ラベル: axisBottomとaxisLeftのlegendプロパティで軸のラベル(売上高・利益率)を表示すること
- 透明度: blendModeを "multiply" またはopacityで重なりを見やすくすること⚠️ このプロンプトはあくまでたたき台です。AIの回答はモデルやバージョン、会話の文脈によって毎回異なります。意図通りに動かない場合は、条件を追記・修正してお使いください。
3. Chart.js (react-chartjs-2)
専用のBubbleチャートタイプでデータの r プロパティがバブル半径(ピクセル)を直接制御
'use client';
import { Bubble } from 'react-chartjs-2';
import { Chart as ChartJS, LinearScale, PointElement, Tooltip, Legend } from 'chart.js';
ChartJS.register(LinearScale, PointElement, Tooltip, Legend);
const data = {
datasets: [
{
label: '事業部A',
data: [
{ x: 1200, y: 18, r: 15 * 0.6 + 3 },
{ x: 850, y: 12, r: 8 * 0.6 + 3 },
{ x: 2100, y: 25, r: 22 * 0.6 + 3 },
{ x: 450, y: 8, r: 4 * 0.6 + 3 },
],
backgroundColor: 'rgba(59, 130, 246, 0.5)',
borderColor: 'rgba(59, 130, 246, 1)',
},
{
label: '事業部B',
data: [
{ x: 1680, y: 20, r: 17 * 0.6 + 3 },
{ x: 950, y: 15, r: 10 * 0.6 + 3 },
{ x: 720, y: 6, r: 6 * 0.6 + 3 },
{ x: 3200, y: 30, r: 28 * 0.6 + 3 },
],
backgroundColor: 'rgba(16, 185, 129, 0.5)',
borderColor: 'rgba(16, 185, 129, 1)',
},
],
};
export function ChartJSBubbleChart() {
return (
<Bubble data={data} options={{
responsive: true,
maintainAspectRatio: false,
scales: {
x: { title: { display: true, text: '売上高(万円)' } },
y: { title: { display: true, text: '利益率(%)' } },
},
}} height={300} />
);
}🤖 AIプロンプトテンプレート
React + Tailwind CSSで、Chart.js(react-chartjs-2)を使ったバブルチャートを実装してください。
- 使用ライブラリ: react-chartjs-2(Bubble)、chart.js(LinearScale、PointElement、Tooltip、Legend)
- サンプルデータ: 2事業部の売上高・利益率・市場シェア(各4件)を{x, y, r}形式で用意すること(rは市場シェアを適切なピクセル値に変換:例 share * 0.6 + 3)
- 第3変数: データの r プロパティでバブルの半径(ピクセル)を制御すること
- インタラクティブ: ホバー時にツールチップで3変数の値を表示すること
- グループ区別: datasetsを事業部ごとに分けてbackgroundColorとborderColorで色分けして表示すること
- レスポンシブ: responsive: true、maintainAspectRatio: falseで親要素に合わせてサイズを調整すること
- 軸ラベル: scalesのx・yそれぞれにtitle.display: trueと軸名(売上高・利益率)を設定すること⚠️ このプロンプトはあくまでたたき台です。AIの回答はモデルやバージョン、会話の文脈によって毎回異なります。意図通りに動かない場合は、条件を追記・修正してお使いください。
4. Victory
VictoryScatterのbubblePropertyで第3変数をバブルサイズに宣言的にマッピング。SVGベースのモジュール式設計
'use client';
import {
VictoryChart, VictoryScatter, VictoryAxis,
VictoryTooltip, VictoryLegend, VictoryTheme,
} from 'victory';
const dataA = [
{ x: 1200, y: 18, z: 15 },
{ x: 850, y: 12, z: 8 },
{ x: 2100, y: 25, z: 22 },
{ x: 450, y: 8, z: 4 },
];
const dataB = [
{ x: 1680, y: 20, z: 17 },
{ x: 950, y: 15, z: 10 },
{ x: 720, y: 6, z: 6 },
{ x: 3200, y: 30, z: 28 },
];
export function VictoryBubbleChart() {
return (
<VictoryChart theme={VictoryTheme.clean} height={280}
padding={{ top: 20, bottom: 60, left: 70, right: 40 }}>
<VictoryLegend x={60} y={5} orientation="horizontal" gutter={20}
data={[
{ name: '事業部A', symbol: { fill: 'rgba(59,130,246,0.6)' } },
{ name: '事業部B', symbol: { fill: 'rgba(16,185,129,0.6)' } },
]} />
<VictoryAxis label="売上高(万円)"
style={{ axisLabel: { padding: 40 } }} />
<VictoryAxis dependentAxis label="利益率(%)"
style={{ axisLabel: { padding: 50 } }} />
<VictoryScatter bubbleProperty="z" maxBubbleSize={25} minBubbleSize={5}
data={dataA}
style={{ data: { fill: 'rgba(59,130,246,0.6)', stroke: '#3b82f6', strokeWidth: 1.5 } }}
labelComponent={<VictoryTooltip />}
labels={({ datum }) => `売上高: ${datum.x}万円 利益率: ${datum.y}%`} />
<VictoryScatter bubbleProperty="z" maxBubbleSize={25} minBubbleSize={5}
data={dataB}
style={{ data: { fill: 'rgba(16,185,129,0.6)', stroke: '#10b981', strokeWidth: 1.5 } }}
labelComponent={<VictoryTooltip />}
labels={({ datum }) => `売上高: ${datum.x}万円 利益率: ${datum.y}%`} />
</VictoryChart>
);
}🤖 AIプロンプトテンプレート
React + Tailwind CSSで、Victoryを使ったバブルチャートを実装してください。
- 使用ライブラリ: victory(VictoryChart、VictoryScatter、VictoryAxis、VictoryTooltip、VictoryLegend)
- サンプルデータ: 2事業部の売上高・利益率・市場シェア(各4件)を{x, y, z}形式で用意すること(z = 市場シェア)
- 第3変数: VictoryScatterのbubblePropertyに "z" を設定し、maxBubbleSize・minBubbleSizeでサイズ範囲を制御すること
- インタラクティブ: labelComponentにVictoryTooltipを設定し、labelsプロパティで3変数の値を表示すること
- グループ区別: VictoryScatterを2つ配置し、styleのdata.fillで事業部ごとに色分けすること
- 凡例: VictoryLegendコンポーネントでグループ名と色を表示すること
- 軸ラベル: VictoryAxisのlabelプロパティで軸名(売上高・利益率)を設定すること⚠️ このプロンプトはあくまでたたき台です。AIの回答はモデルやバージョン、会話の文脈によって毎回異なります。意図通りに動かない場合は、条件を追記・修正してお使いください。
5. ApexCharts (react-apexcharts)
[x, y, バブルサイズ] の3要素配列でバブルチャートを簡潔に記述。ズーム・パン機能も標準装備
チャートを読み込み中...
'use client';
import dynamic from 'next/dynamic';
const Chart = dynamic(() => import('react-apexcharts'), { ssr: false });
export function ApexBubbleChart() {
const options = {
chart: { type: 'bubble' as const, toolbar: { show: false } },
xaxis: { title: { text: '売上高(万円)' }, min: 0, max: 3500 },
yaxis: { title: { text: '利益率(%)' }, min: 0, max: 35 },
colors: ['#3b82f6', '#10b981'],
fill: { opacity: 0.6 },
dataLabels: { enabled: false },
tooltip: { z: { title: '市場シェア: ' } },
};
const series = [
{ name: '事業部A', data: [[1200, 18, 15], [850, 12, 8], [2100, 25, 22], [450, 8, 4]] },
{ name: '事業部B', data: [[1680, 20, 17], [950, 15, 10], [720, 6, 6], [3200, 30, 28]] },
];
return <Chart type="bubble" options={options} series={series} height={300} width="100%" />;
}🤖 AIプロンプトテンプレート
React + Tailwind CSSで、ApexCharts(react-apexcharts)を使ったバブルチャートを実装してください。
- 使用ライブラリ: react-apexcharts(dynamic importでSSR無効化)
- chart.type: 'bubble' を指定すること
- サンプルデータ: 2事業部の [売上高, 利益率, 市場シェア] の配列形式(各4件)で用意すること
- xaxis.title・yaxis.title で軸ラベルを表示すること
- fill.opacity: 0.6 でバブルの透明度を設定すること
- tooltip.z.title でバブルサイズの説明を表示すること
- dataLabels: { enabled: false } でデータラベルを非表示にすること⚠️ このプロンプトはあくまでたたき台です。AIの回答はモデルやバージョン、会話の文脈によって毎回異なります。意図通りに動かない場合は、条件を追記・修正してお使いください。
ライブラリ比較
| ライブラリ | 第3変数対応 | インタラクション | スケール制御 | おすすめ用途 |
|---|---|---|---|---|
| Recharts | ◎(ZAxis) | ◯ | ◯(range指定) | ダッシュボード |
| Nivo | ◯(nodeSize関数) | ◎ | ◎(関数で自由設定) | 分析レポート |
| Chart.js | ◎(r値) | ◯ | △(ピクセル直指定) | 大量データの可視化 |
| Victory | ◎(bubbleProperty) | ◯ | ◯(min/maxBubbleSize) | モジュール式カスタマイズ |
| ApexCharts | ◎(3要素配列) | ◎(ズーム・パン) | ◯(自動スケール) | ダッシュボード・業務アプリ |
バブルチャートの選択ポイント
- •Recharts: ZAxisのdataKeyとrangeで第3変数を直感的に設定可能。 Reactプロジェクトのダッシュボードや管理画面に最適。
- •Nivo: nodeSizeに関数を渡すことでスケールを自由にカスタマイズ可能。 美しいアニメーションと高度なインタラクションを求める分析レポートに最適。
- •Chart.js: 専用のBubbleチャートタイプでシンプルに実装可能。 Canvas描画で大量データでも高パフォーマンスを維持。ただしrはピクセル値のため データスケールへの変換が必要。
- •Victory: bubblePropertyにデータキーを指定するだけで第3変数のバブルサイズ化が完結。 モジュール式設計でコンポーネントを自由に組み合わせられ、 TypeScriptサポートも充実。D3非依存で軽量。
- •ApexCharts: [x, y, サイズ] の3要素配列で簡潔にバブルチャートを実装可能。 ズーム・パン機能が標準装備され、インタラクティブなデータ探索に最適。
バブルチャートの典型的な使用例
📦 製品ポートフォリオ分析
売上・利益率・市場シェアの3変数で各製品の位置づけを俯瞰的に把握
🌍 国別・地域別比較
GDP・一人当たり所得・人口の3変数で国の経済状況を比較(バブルサイズ=人口)
👥 顧客セグメント分析
購買頻度・平均単価・顧客数で顧客グループの特性と規模を同時に可視化
⚠️ リスクマトリクス
発生確率・影響度・対応コストでリスクの優先度を視覚的に評価
⚠️ バブルチャート使用時の注意点
- •バブルサイズは面積ではなく半径で比較してしまいがちなため、凡例でスケールを明示する
- •バブルが重なる場合は透明度(opacity)を調整して後ろのバブルも視認できるようにする
- •散布図と同じく相関関係と因果関係を混同しないよう注意する
- •バブルサイズの差が大きすぎると小さいバブルが見えにくくなるためrangeや最小サイズを適切に設定する
- •地理座標ベースのバブルマップには別途マップライブラリ(Leaflet等)の利用を検討する
バブルチャート(気泡グラフ)は、散布図に3つ目の変数をバブルの大きさで表現したグラフ。X軸・Y軸・バブルサイズの3次元のデータを一度に可視化できる。
市場規模と成長率と競合数の可視化・国別GDPと人口と面積の比較など、3変数の相関関係を探る分析に使われる。
- •基本型(サイズ比例)
- •色分け型(カテゴリ別)
- •ラベル付き型
- •アニメーション型(時系列変化)
- •インタラクティブ型(クリック詳細)
📊 使用しているサンプルデータ(クリックで表示)
2事業部の製品ポートフォリオ分析データ(各4件)を使用しています。 X軸:売上高(万円)、Y軸:利益率(%)、バブルサイズ:市場シェア(%)の3変数を同時に表現します。
関連する逆引きリファレンス
- → 色・スタイルのカスタマイズ(borderColor・fillOpacity など)
- → ツールチップのカスタマイズ(カスタムHTML・フォーマッタ)
- → 軸(Axis)の設定(ラベルフォーマット・対数スケール・複数軸)
- → レスポンシブ対応(コンテナ追従・アスペクト比・リサイズ)
- → アニメーション・トランジション(初期描画・データ更新・イージング)
- → 凡例(Legend)の配置・スタイル(位置・アイコン・系列トグル)
- → データラベルの表示(値・位置・フォーマッタ)
- → クリックイベント・インタラクション(クリック・ホバー・ブラシ選択)
- → グリッド線のカスタマイズ(表示制御・線スタイル・リファレンスライン)