Highcharts 气泡图

Highcharts 气泡图(Bubble Chart)详解

Highcharts 气泡图是一种强大的三维数据可视化图表,通过气泡的 X 坐标Y 坐标气泡大小(Z 值) 同时展示三个变量的关系。第四维度还可以用颜色表示(colorAxis)。常用于:

  • 国家/城市对比:X=人均GDP,Y=预期寿命,Z=人口
  • 企业分析:X=营收,Y=利润率,Z=市值
  • 产品评估:X=价格,Y=评分,Z=销量
  • 风险矩阵:X=发生概率,Y=影响程度,Z=潜在损失

必须引入模块

气泡图需要额外加载 highcharts-more.js

<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/highcharts-more.js"></script>  <!-- 必须 -->

1. 完整基础气泡图示例(带标签 + 缩放)

<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <title>Highcharts 气泡图示例</title>
    <script src="https://code.highcharts.com/highcharts.js"></script>
    <script src="https://code.highcharts.com/highcharts-more.js"></script>
</head>
<body>
    <div id="container" style="width: 900px; height: 600px; margin: 50px auto;"></div>

    <script>
        Highcharts.chart('container', {
            chart: {
                type: 'bubble',                  // 关键:'bubble'
                zoomType: 'xy',                  // 支持拖拽缩放(大数据量时非常实用)
                backgroundColor: '#ffffff',
                borderRadius: 10
            },
            title: {
                text: '2025年全球主要经济体三维对比',
                style: { fontSize: '22px', fontWeight: 'bold' }
            },
            subtitle: {
                text: 'X轴:人均GDP(万美元) | Y轴:预期寿命(岁) | 气泡大小:人口(亿人)'
            },
            xAxis: {
                title: { text: '人均GDP(万美元)' },
                gridLineWidth: 1,
                min: 0,
                max: 12
            },
            yAxis: {
                title: { text: '预期寿命(岁)' },
                min: 65,
                max: 85
            },
            tooltip: {
                useHTML: true,
                headerFormat: '<b>{point.name}</b><br>',
                pointFormat: '<span style="font-size:14px">人均GDP:{point.x} 万美元</span><br>' +
                             '预期寿命:{point.y} 岁<br>' +
                             '人口:{point.z} 亿人'
            },
            plotOptions: {
                bubble: {
                    minSize: 15,                     // 最小气泡直径
                    maxSize: '22%',                  // 最大气泡直径(相对图表区域)
                    zMin: 0,
                    zMax: 15,
                    marker: {
                        fillOpacity: 0.7             // 透明度,避免重叠看不清
                    },
                    dataLabels: {
                        enabled: true,
                        format: '{point.name}',
                        style: { color: '#333', fontWeight: 'bold', textOutline: 'none' }
                    }
                }
            },
            series: [{
                name: '国家',
                colorByPoint: true,              // 每个气泡自动不同颜色
                data: [
                    { x: 8.5, y: 82.8, z: 14.7, name: '中国' },
                    { x: 7.3, y: 79.5, z: 14.2, name: '印度' },
                    { x: 9.0, y: 78.3, z: 3.4,  name: '美国' },
                    { x: 6.2, y: 83.5, z: 1.24, name: '日本' },
                    { x: 6.0, y: 82.0, z: 0.83, name: '德国' },
                    { x: 5.5, y: 81.2, z: 0.68, name: '英国' },
                    { x: 5.1, y: 80.8, z: 0.67, name: '法国' },
                    { x: 2.0, y: 77.5, z: 2.9,  name: '巴西' },
                    { x: 1.2, y: 74.0, z: 2.4,  name: '尼日利亚' }
                ]
            }]
        });
    </script>
</body>
</html>

2. 多系列气泡图(分组展示)

series: [
    {
        name: '亚洲',
        color: '#e74c3c',
        data: [
            { x: 8.5, y: 82.8, z: 14.7, name: '中国' },
            { x: 7.3, y: 79.5, z: 14.2, name: '印度' },
            { x: 6.2, y: 83.5, z: 1.24, name: '日本' }
        ]
    },
    {
        name: '欧美',
        color: '#3498db',
        data: [
            { x: 9.0, y: 78.3, z: 3.4, name: '美国' },
            { x: 6.0, y: 82.0, z: 0.83, name: '德国' },
            { x: 5.5, y: 81.2, z: 0.68, name: '英国' }
        ]
    }
]

3. 数据格式

每点支持:

  • 数组:[x, y, z][x, y, z, name]
  • 对象(推荐):
  { x: 8.5, y: 82.8, z: 14.7, name: '中国' }

4. 常用配置速查表

配置项推荐值/说明
chart.type'bubble'
chart.zoomType'xy'(强烈推荐)
plotOptions.bubble.minSize10~20 像素
plotOptions.bubble.maxSize'15%' ~ '25%'
plotOptions.bubble.zMin/zMax控制 Z 值映射范围,避免极端值
marker.fillOpacity0.5~0.8(透明度)
colorByPointtrue(单系列自动配色)
dataLabels.enabledtrue(显示名称)

气泡图结合缩放功能是处理密集数据的绝佳选择,交互体验优秀。

如果你需要:

  • 动态实时气泡图(新气泡不断出现)
  • 用颜色表示第四维度(colorAxis)
  • 负值气泡处理
  • 3D 气泡图(需 highcharts-3d.js)

告诉我你的具体场景,我可以提供完整代码示例!

文章已创建 3511

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

相关文章

开始在上面输入您的搜索词,然后按回车进行搜索。按ESC取消。

返回顶部