笛卡尔坐标
气泡图
type: 'bubble'散点图,其中标记半径编码第三个值(z),使用平方根缩放使面积与z成比例。
编辑右侧的JSON并按Run(或⌘/Ctrl + Enter)——数据、标题、类别和颜色全部实时更新。
实时
气泡图
编辑 · JSON
数据格式
[[x, y, z]] · { x, y, z, name? }
数据结构
传入图表的 JSON——可直接放进你的 series。
data: [
[2, 35, 12],
[4, 52, 20],
[8, 75, 34]
]示例
import KatuCharts from 'katucharts.js';
KatuCharts.chart('container', {
chart: { type: 'bubble' },
series: [{ name: '团队', data: [[2, 35, 12], [4, 52, 20], [8, 75, 34]] }]
});类型特定选项
| 选项 | 描述 |
|---|---|
sizeBy | 'area'(默认)或'width'。 |
minSize / maxSize | 气泡大小范围(像素或'8%')。 |
zMin / zMax / zThreshold | Z范围界限和负值阈值。 |
displayNegative / sizeByAbsoluteValue | 显示负z气泡 / 按|z|调整大小。 |
变体
尺寸图例
将每个尺寸显示为单独的参考气泡并在旁边标注数值(bubbleLegend.layout: 'separate'),帮助读者解读气泡大小。
KatuCharts.chart('container', {
chart: { type: 'bubble' },
legend: {
enabled: true, align: 'center', verticalAlign: 'bottom',
bubbleLegend: { enabled: true, layout: 'separate', labels: { format: '{value}' } }
},
series: [{ name: '员工人数', data: [[2, 35, 12], [4, 52, 20], [8, 75, 34]] }]
});侧边尺寸图例
将单独的尺寸气泡放在右侧的垂直图例中——同样的图例也可放在底部或左侧。
KatuCharts.chart('container', {
chart: { type: 'bubble' },
legend: {
layout: 'vertical', align: 'right', verticalAlign: 'middle',
bubbleLegend: { enabled: true, layout: 'separate' }
},
series: [{ name: '员工人数', data: [[2, 35, 12], [4, 52, 20], [8, 75, 34]] }]
});命名气泡
按数据点为气泡着色,并用名称标注每个气泡。
KatuCharts.chart('container', {
chart: { type: 'bubble' },
series: [{
colorByPoint: true,
dataLabels: { enabled: true, format: '{point.name}' },
data: [
{ x: 2, y: 35, z: 12, name: 'Alpha' },
{ x: 4, y: 52, z: 20, name: 'Bravo' }
]
}]
});Common errors
- Why does my 气泡图 chart render as a line chart?
- The chart type was not registered. KatuCharts logs "KatuCharts: unknown series type "<type>", falling back to line" and draws a line chart rather than throwing. Import the module the type belongs to — for example `import 'katucharts.js/bio';` — before creating the chart.
- Why do I get "Cannot read properties of null (reading 'appendChild')"?
- The container element does not exist when the chart is created. Create the chart after the element is in the DOM: in React that means inside useEffect, not during render.
- Why is the chart rendering with zero height?
- The container has no height. A div with no content collapses to zero. Give it a height in CSS, or pass `chart: { height: 400 }` in the options.
FAQ
- How do I create a 气泡图 chart in JavaScript?
- Install with `npm install katucharts.js`, then call KatuCharts.chart(container, { chart: { type: 'bubble' }, series: [...] }).
- Why does my 气泡图 chart render as a line chart?
- The chart type was not registered. KatuCharts logs "KatuCharts: unknown series type "<type>", falling back to line" and draws a line chart rather than throwing. Import the module the type belongs to — for example `import 'katucharts.js/bio';` — before creating the chart.
- Why do I get "Cannot read properties of null (reading 'appendChild')"?
- The container element does not exist when the chart is created. Create the chart after the element is in the DOM: in React that means inside useEffect, not during render.
- Why is the chart rendering with zero height?
- The container has no height. A div with no content collapses to zero. Give it a height in CSS, or pass `chart: { height: 400 }` in the options.