You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

3D Highcharts堆叠柱状图折线无法显示在前方问题求助

解决Highcharts 3D堆叠柱状图中折线被遮挡的问题

我在实现一个包含堆叠柱状图(堆叠项为'Utilized'、'Not Utilized'、'Offline')和平均值折线的图表,X轴对应一天的0-23小时。非3D模式下折线能正常显示在柱状图前方,但启用3D配置后,即便给折线设置了更高的zIndex,仍会被柱子遮挡。

问题原因

Highcharts的3D柱状图会在独立的3D渲染容器中绘制,普通的zIndex无法穿透这个容器的层级,导致折线被压在柱子下方。

解决方案

调整柱状图的groupZPadding参数,让柱子整体向3D空间后方偏移,同时保持折线的高zIndex,即可让折线显示在前方:

Highcharts.chart('container', {
    chart: {
        type: 'column',
        options3d: {
            enabled: true,
            alpha: 10,
            beta: 25,
            depth: 50,
            viewDistance: 25
        }
    },
    title: {
        text: 'Utilization Overview (3D)'
    },
    xAxis: {
        categories: Array.from({ length: 24 }, (_, i) => i.toString()), // Hours from 0 to 23
        title: {
            text: 'Hour of the Day'
        }
    },
    yAxis: {
        min: 0,
        title: {
            text: 'Utilization'
        }
    },
    tooltip: {
        shared: false,
        formatter: function() {
            if (this.series.type === 'line') {
                return `<b>Average</b>: ${this.y}`;
            } else {
                return `<b>${this.series.name}</b>: ${this.y}`;
            }
        }
    },
    plotOptions: {
        column: {
            stacking: 'normal',
            depth: 25,
            groupZPadding: -15 // 新增:让柱子向后偏移,给折线留出前方空间
        },
        line: {
            marker: {
                enabled: false
            },
            zIndex: 10 
        }
    },
    series: [{
        name: 'Utilized',
        data: [5, 3, 4, 7, 2, 6, 8, 7, 5, 4, 6, 8, 9, 10, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3],
        stack: 'utilization',
        zIndex: 1 
    }, {
        name: 'Not Utilized',
        data: [2, 2, 3, 2, 1, 1, 2, 1, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
        stack: 'utilization',
        zIndex: 1 
    }, {
        name: 'Offline',
        data: [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
        stack: 'utilization',
        zIndex: 1 
    }, {
        name: 'Average',
        type: 'line',
        data: [4, 2.67, 2.67, 3.33, 1.33, 2.67, 3.67, 3.00, 2.67, 2.33, 2.67, 3.00, 3.67, 4.00, 4.67, 4.00, 4.00, 3.00, 2.67, 2.00, 2.00, 2.00, 2.00, 1.67],
        zIndex: 10
    }]
});

说明

  • groupZPadding的数值可根据3D视角调整,负数表示向3D空间后方移动柱子,正数则向前。
  • 保持折线的zIndex高于柱子的zIndex,确保在2D层级上折线也处于优先渲染位置。

内容的提问来源于stack exchange,提问作者Asif Mahmud

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.14 23:13:12