首页 > 解决方案 > Highchart - 如何控制系列之间的差距

问题描述

在 Highcharts 中,如何控制类别之间的差距?

我在下面用蓝色突出显示了我正在谈论的区域: 在此处输入图像描述

我想让我的 highchart 图表差距看起来像左下角的这个 powerpoint 版本。PowerPoint 中的条形图一直延伸到绘图区域的尽头,但高图有这么大的差距。

在此处输入图像描述

https://jsfiddle.net/15u0r64s/

    Highcharts.chart('container', {
        chart: {
            type: 'bar'
        },
        title: {
            text: 'Historic World Population by Region'
        },
        subtitle: {
            text: 'Source: <a href="https://en.wikipedia.org/wiki/World_population">Wikipedia.org</a>'
        },
        xAxis: {
            categories: ['Total', 'Male', 'Female', 'Other'],
            title: {
                text: null
            }
        },
        yAxis: {
            min: 0,
            title: {
                text: 'Population (millions)',
                align: 'high'
            },
            labels: {
                overflow: 'justify'
            }
        },
        tooltip: {
            valueSuffix: ' millions'
        },
        plotOptions: {
            bar: {
                dataLabels: {
                    enabled: true
                }
            }
        },
        legend: {
            layout: 'vertical',
            align: 'right',
            verticalAlign: 'top',
            x: -40,
            y: 80,
            floating: true,
            borderWidth: 1,
            backgroundColor:
                Highcharts.defaultOptions.legend.backgroundColor || '#FFFFFF',
            shadow: true
        },
        credits: {
            enabled: false
        },
        series: [{
            name: 'Total',
            data: [10, 20, 31, '']
        }, {
            name: 'Male',
            data: [10, 20, 60, 2]
        }, {
            name: 'Female',
            data: [10, 20, 61, '']
        }, {
            name: 'Other',
            data: [10, 20, 65, 4]
        }]
    });

标签: highcharts

解决方案


您需要编辑groupPaddingpointPadding属性:

plotOptions: {
  bar: {
    groupPadding: 0.05,
    pointPadding: 0
  }
}

现场演示: https ://jsfiddle.net/BlackLabel/oqpxmL18/

API参考:

https://api.highcharts.com/highcharts/series.bar.groupPadding

https://api.highcharts.com/highcharts/series.bar.pointPadding


推荐阅读