Chart.js バブルチャート
バブルチャートは、3つの変数の関係を表示するために使用されます。
バブルの位置は最初の2つの変数によって決まり、X軸とY軸に対応し、3番目のパラメータがバブルのサイズになります。
{
// X 轴对应值
x: number,
// Y 轴对应值
y: number,
// 气泡半径,单位为像素
r: number
}
バブルチャートのtype属性はbubble、typeはチャートタイプを記述します。
const config = {
type: 'bubble',
data: data,
options: {}
};
次に、簡単なバブルチャートを作成します:
サンプル
const ctx = document.getElementById('myChart');
const data = {
datasets: [{
label: 'バブルチャートのサンプル',
data: [{
x: 20, // X軸
y: 30, // Y軸
r: 15 // バブルの半径
}, {
x: 30,
y: 20,
r: 20
}, {
x: 40,
y: 10,
r: 10
}],
backgroundColor: 'rgb(255, 99, 132)'
}]
};
const config = {
type: 'bubble', // チャートタイプを設定
data: data, // データセットを設定
options: {
},
};
const myChart = new Chart(ctx, config);
const data = {
datasets: [{
label: 'バブルチャートのサンプル',
data: [{
x: 20, // X軸
y: 30, // Y軸
r: 15 // バブルの半径
}, {
x: 30,
y: 20,
r: 20
}, {
x: 40,
y: 10,
r: 10
}],
backgroundColor: 'rgb(255, 99, 132)'
}]
};
const config = {
type: 'bubble', // チャートタイプを設定
data: data, // データセットを設定
options: {
},
};
const myChart = new Chart(ctx, config);
試してみる »
上記のサンプルの出力結果は次のとおりです:
その他の拡張