パラレル座標ライブラリ比較
3つのアプローチで多変量データのパターンや相関を可視化し、実装方法とスタイルを比較
📊 使用しているサンプルデータ
自動車の5つのスペック指標(馬力・燃費・重量・加速・価格)を持つ10車種のデータを使用しています。各指標は異なるスケールを持ちます。
[
{
"name": "車種A",
"horsepower": 130,
"fuelEfficiency": 18,
"weight": 1800,
"acceleration": 12,
"price": 280
},
{
"name": "車種B",
"horsepower": 165,
"fuelEfficiency": 14,
"weight": 2100,
"acceleration": 10,
"price": 420
},
{
"name": "車種C",
"horsepower": 95,
"fuelEfficiency": 24,
"weight": 1400,
"acceleration": 16,
"price": 180
},
{
"name": "車種D",
"horsepower": 210,
"fuelEfficiency": 10,
"weight": 2400,
"acceleration": 8,
"price": 680
},
{
"name": "車種E",
"horsepower": 110,
"fuelEfficiency": 21,
"weight": 1600,
"acceleration": 14,
"price": 220
},
{
"name": "車種F",
"horsepower": 185,
"fuelEfficiency": 12,
"weight": 2200,
"acceleration": 9,
"price": 520
},
{
"name": "車種G",
"horsepower": 75,
"fuelEfficiency": 28,
"weight": 1200,
"acceleration": 18,
"price": 150
},
{
"name": "車種H",
"horsepower": 145,
"fuelEfficiency": 16,
"weight": 1950,
"acceleration": 11,
"price": 350
},
{
"name": "車種I",
"horsepower": 230,
"fuelEfficiency": 9,
"weight": 2600,
"acceleration": 7,
"price": 780
},
{
"name": "車種J",
"horsepower": 88,
"fuelEfficiency": 26,
"weight": 1350,
"acceleration": 17,
"price": 165
}
]1. Nivo(@nivo/parallel-coordinates)
@nivo/parallel-coordinatesパッケージでパラレル座標をネイティブサポート。variablesに軸の定義を渡すだけで各軸のスケールを自動正規化して描画。ラインの色・透明度・曲線の種類(linear・monotoneX)などのカスタマイズが豊富。ホバー時のハイライトも標準対応。
'use client';
import { ResponsiveParallelCoordinates } from '@nivo/parallel-coordinates';
const data = [
{ product: 'A', sales: 85, cost: 42, profit: 43, satisfaction: 4.2 },
{ product: 'B', sales: 62, cost: 38, profit: 24, satisfaction: 3.8 },
{ product: 'C', sales: 91, cost: 55, profit: 36, satisfaction: 4.5 },
{ product: 'D', sales: 48, cost: 25, profit: 23, satisfaction: 3.5 },
{ product: 'E', sales: 75, cost: 48, profit: 27, satisfaction: 4.0 },
];
const variables = [
{ key: 'sales', type: 'linear' as const, min: 0, max: 100, ticksPosition: 'before' },
{ key: 'cost', type: 'linear' as const, min: 0, max: 70, ticksPosition: 'before' },
{ key: 'profit', type: 'linear' as const, min: 0, max: 60, ticksPosition: 'before' },
{ key: 'satisfaction', type: 'linear' as const, min: 1, max: 5, ticksPosition: 'before' },
];
export function NivoParallelCoordinates() {
return (
<div style={{ height: 300 }}>
<ResponsiveParallelCoordinates
data={data}
variables={variables}
margin={{ top: 50, right: 60, bottom: 50, left: 60 }}
colors={{ scheme: 'category10' }}
strokeWidth={2}
lineOpacity={0.5}
curve="monotoneX"
/>
</div>
);
}🤖 AIプロンプトテンプレート
React + Tailwind CSSで、Nivo(@nivo/parallel-coordinates)を使ったパラレル座標チャートを実装してください。 - 使用ライブラリ: @nivo/parallel-coordinates の ResponsiveParallelCoordinates コンポーネント - サンプルデータ: 自動車スペック10車種(馬力・燃費・重量・加速性能・価格)を用意すること - インタラクティブ: ホバー時に対象ラインをハイライト表示すること(標準搭載) - 軸: variables プロパティに id・min・max・label を定義して軸ごとに独立したスケールを自動設定すること - レスポンシブ: ResponsiveParallelCoordinates を使って親要素の幅に応じてサイズが変わるよう対応すること - スタイリング: colors・curve・lineOpacity・lineWidth を設定し、curve="monotoneX" で滑らかなラインにすること
⚠️ このプロンプトはあくまでたたき台です。AIの回答はモデルやバージョン、会話の文脈によって毎回異なります。意図通りに動かない場合は、条件を追記・修正してお使いください。
2. D3.js(カスタム実装)
D3.jsのスケール関数で各軸を独立して正規化し、SVG描画をReactで制御するカスタム実装。d3-brushを組み合わせることで各軸にブラシ操作(範囲選択によるフィルタリング)を追加できる。実装コストは最も高いが、インタラクティブなデータ探索ツールとして最大の表現力を発揮。
'use client';
// D3.js カスタム平行座標プロット実装
const data = [
{ sales: 85, cost: 42, profit: 43, satisfaction: 4.2 },
{ sales: 62, cost: 38, profit: 24, satisfaction: 3.8 },
{ sales: 91, cost: 55, profit: 36, satisfaction: 4.5 },
{ sales: 48, cost: 25, profit: 23, satisfaction: 3.5 },
{ sales: 75, cost: 48, profit: 27, satisfaction: 4.0 },
];
const axes = [
{ key: 'sales', label: '売上', min: 0, max: 100 },
{ key: 'cost', label: 'コスト', min: 0, max: 70 },
{ key: 'profit', label: '利益', min: 0, max: 60 },
{ key: 'satisfaction', label: '満足度', min: 1, max: 5 },
];
const colors = ['#3b82f6', '#10b981', '#8b5cf6', '#f97316', '#ec4899'];
function normalize(value: number, min: number, max: number, height: number): number {
return height - ((value - min) / (max - min)) * height;
}
export function D3ParallelCoordinates() {
const width = 400, height = 220;
const marginX = 40, marginY = 30;
const chartW = width - marginX * 2;
const chartH = height - marginY * 2;
const step = chartW / (axes.length - 1);
return (
<svg viewBox={`0 0 ${width} ${height + marginY}`} className="w-full">
<g transform={`translate(${marginX}, ${marginY})`}>
{data.map((d, i) => {
const points = axes.map((ax, j) =>
`${j * step},${normalize((d as any)[ax.key], ax.min, ax.max, chartH)}`
).join(' ');
return <polyline key={i} points={points} fill="none" stroke={colors[i]} strokeWidth={1.5} opacity={0.6} />;
})}
{axes.map((ax, j) => (
<g key={ax.key} transform={`translate(${j * step}, 0)`}>
<line y1={0} y2={chartH} stroke="#d1d5db" strokeWidth={1} />
<text y={-8} textAnchor="middle" fontSize={10} fill="#374151">{ax.label}</text>
</g>
))}
</g>
</svg>
);
}🤖 AIプロンプトテンプレート
React + Tailwind CSSで、D3.js(カスタム実装)を使ったパラレル座標チャートを実装してください。 - 使用ライブラリ: 外部ライブラリなし。各軸のmin・maxから値を0〜1に正規化するカスタム関数と、SVGのpolylineで描画するReact + SVGカスタム実装 - サンプルデータ: 自動車スペック10車種(馬力・燃費・重量・加速性能・価格)を用意すること - インタラクティブ: ホバー時に対象ラインを強調表示し他ラインを薄くするハイライト処理をuseStateで実装すること - 軸: 各軸に縦線・目盛り・ラベルを表示し、d3-brushと組み合わせることで範囲フィルタリングを追加できること - レスポンシブ: viewBox を使って親要素の幅に応じてサイズが変わるよう対応すること - スタイリング: 各データ系列を識別しやすい10色のカラーパレットで色分けすること
⚠️ このプロンプトはあくまでたたき台です。AIの回答はモデルやバージョン、会話の文脈によって毎回異なります。意図通りに動かない場合は、条件を追記・修正してお使いください。
3. カスタムReact実装(SVG)
外部ライブラリに依存せずReact + SVGでカスタム実装。各軸のmin・maxから値を0〜1に正規化し、SVGのpolylineで各データポイントを結ぶシンプルな実装。バンドルサイズへの影響がなく、基本的なパラレル座標を最小限のコードで実現できる。
(value - min) / (max - min) で 各軸を0〜1に正規化し、polyline で描画するだけの最小実装。'use client';
// 外部依存ゼロのReact + SVGカスタム実装
const data = [
{ sales: 85, cost: 42, profit: 43, satisfaction: 4.2 },
{ sales: 62, cost: 38, profit: 24, satisfaction: 3.8 },
{ sales: 91, cost: 55, profit: 36, satisfaction: 4.5 },
{ sales: 48, cost: 25, profit: 23, satisfaction: 3.5 },
];
const axes = [
{ key: 'sales', label: '売上', min: 0, max: 100 },
{ key: 'cost', label: 'コスト', min: 0, max: 70 },
{ key: 'profit', label: '利益', min: 0, max: 60 },
{ key: 'satisfaction', label: '満足度', min: 1, max: 5 },
];
const colors = ['#3b82f6', '#10b981', '#8b5cf6', '#f97316'];
const normalize = (v: number, min: number, max: number, h: number) =>
h - ((v - min) / (max - min)) * h;
export function CustomParallelCoordinates() {
const w = 400, h = 200, mx = 40, my = 30;
const chartW = w - mx * 2;
const chartH = h - my * 2;
const step = chartW / (axes.length - 1);
return (
<svg viewBox={`0 0 ${w} ${h + my}`} className="w-full">
<g transform={`translate(${mx}, ${my})`}>
{data.map((d, i) => (
<polyline key={i}
points={axes.map((ax, j) =>
`${j * step},${normalize((d as any)[ax.key], ax.min, ax.max, chartH)}`
).join(' ')}
fill="none" stroke={colors[i]} strokeWidth={2} opacity={0.7} />
))}
{axes.map((ax, j) => (
<g key={ax.key} transform={`translate(${j * step}, 0)`}>
<line y1={0} y2={chartH} stroke="#9ca3af" />
<text y={-6} textAnchor="middle" fontSize={10} fill="#374151">{ax.label}</text>
</g>
))}
</g>
</svg>
);
}🤖 AIプロンプトテンプレート
React + Tailwind CSSで、カスタムReact実装(SVG)を使ったパラレル座標チャートを実装してください。 - 使用ライブラリ: 外部ライブラリなし。React + SVGのみで軸の正規化・グリッド配置・ライン描画をすべて自前実装すること - サンプルデータ: 自動車スペック10車種(馬力・燃費・重量・加速性能・価格)を用意すること - インタラクティブ: なし(表示専用の最小実装) - 軸: (value - min) / (max - min) で各軸を0〜1に正規化し、SVGのpolylineで各データポイントを結ぶこと - レスポンシブ: viewBox を使って親要素の幅に応じてサイズが変わるよう対応すること - スタイリング: 各データ系列を識別しやすい色で strokeOpacity を設定してラインを描画すること
⚠️ このプロンプトはあくまでたたき台です。AIの回答はモデルやバージョン、会話の文脈によって毎回異なります。意図通りに動かない場合は、条件を追記・修正してお使いください。
ライブラリ比較
| アプローチ | レンダリング | 対応状況 | ブラシ操作 | おすすめ用途 |
|---|---|---|---|---|
| Nivo | SVG | ◎ 専用パッケージ | △ | デザイン重視のダッシュボード |
| D3.js カスタム | SVG | ◎ 完全カスタム | ◎ | インタラクティブな分析ツール |
| カスタムReact実装 | SVG | ◯ 基本機能 | ✕ | 軽量・シンプルな表示用途 |
選択のポイント
- •Nivo: @nivo/parallel-coordinatesが最もバランスが良く、導入コストを抑えつつ高品質な表示を実現。閲覧メインのダッシュボードに最適。
- •D3.js: ブラシ操作によるインタラクティブなフィルタリングが必要な分析ツールに選択。実装コストは最も高いが表現力も最大。
- •カスタムReact実装: 外部依存を排除したい場合やシンプルな表示のみ必要な場合に。最小限のコードで基本的なパラレル座標を実現できる。
典型的な使用例
- 🚗製品スペック比較: 複数の製品を多軸のスペックで同時に比較・パターン発見
- 👥顧客セグメント分析: 年齢・購買頻度・単価・LTVなど複数指標でセグメントの特徴を把握
- 🔬多変量データ探索: 機械学習の特徴量エンジニアリングでの変数間の相関パターン確認
- 📊パフォーマンス評価: 複数のKPIを持つチーム・個人の総合評価を視覚的に比較
⚠️ 使用時の注意点
- •軸ごとにスケールが異なるため、必ず正規化(0〜1)して描画する
- •軸の順序によってパターンの見え方が大きく変わるため、相関が強い軸を隣接させると読みやすい
- •データ件数が多すぎるとラインが重なって見づらくなるため、透明度を下げるか代表的なデータに絞る
- •ラインの色でカテゴリーを区別する場合、色覚多様性に配慮したカラーパレットを選択する