首页 > 解决方案 > 如何自定义 Highcharts.js 中的条形宽度和条形间距

问题描述

我想做这样的东西

在此处输入图像描述

这是我的示例代码:-

           plotOptions: {
                series: {
                    borderWidth: 0,
                    pointWidth: 80,
                    groupPadding: 4,
                    dataLabels: {
                        enabled: true,
                        format: '{point.y:.1f}%',
                    }
                }
            },

我对 pointWidh 和 groupPadding 属性感到困惑,一次只有一个属性可以工作。当只给定pointWidth时,宽度适用,而当只给groupPadding时,它也适用。但我希望这些属性不能同时适用。我在做什么错这里是重现示例 https://jsfiddle.net/gh/get/library/pure/highcharts/highcharts/tree/master/samples/highcharts/plotoptions/column-pointpadding-025/

标签: reactjshighcharts

解决方案


我已经编写了完整的工作代码,如果有不清楚的地方请告诉我。

Highcharts.chart('container', {
    chart: {
        type: 'column'
    },
    xAxis: {
        categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
    },

    plotOptions: {
        series: {
            pointPadding: 0,
            borderRadius: 8,
            pointWidth: 50
        }
    },

    series: [{
    data: [{y: 29.9, color: '#ff7841'}, {y: 71.5, color: '#ffa03c'}, {y: 106.4, color: '#ffbb39'}, {y: 129.2, color: '#b0bf05'}, {y:144.0, color: '#00bcb9'}, {y: 176.0, color: '#05a7cd'}, {y: 135.6, color: '#4d7ed7'}]
    }]
});
<script src="https://code.highcharts.com/highcharts.js"></script>

<div id="container" style="height: 400px"></div>


这个小提琴似乎非常接近你的设计。

https://jsfiddle.net/sirajalam049/zxw0nLpr/7/

在此处输入图像描述


推荐阅读