Maximum bar width in Highcharts column charts

后端 未结 8 1649
梦毁少年i
梦毁少年i 2021-02-18 14:20

I\'m using Highcharts to create some vertical bars (a.k.a. \"column charts\") a lot like here: highcharts.com/demo/column-basic

Thing is, sometimes there are 30 bars in

8条回答
  •  旧巷少年郎
    2021-02-18 14:41

    I used the spacingTop attribute to enforce a maximum pointWidth on a bar chart:

    if (series[0].data[0].pointWidth > maximumBarWidth) {
         this.options.chart.spacingTop = this.options.chart.height - (maximumBarWidth * series.length) - 30;
         this.isDirtyBox = true;
         this.redraw();
    }
    

    So if there is one Bar over a certain Width the spacing will be adjusted and the chart is drawn smaller.

    This does not change the size of the container but keeps the bars beneath a certain size and your pointPadding and groupPadding will not be affected.

    You could do the same with spacingRight and would have a consistent Chart without ugly spaces between the bars.

提交回复
热议问题