Maximum bar width in Highcharts column charts

后端 未结 8 1654
梦毁少年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:45
    function(chart){
            var series = chart.series[0];
            //--- Enforce a Maximum bar width
            if (series && series.data.length) {
                if (series.data[0].pointWidth  >  MaximumBarWidth) {
                    for(var i=0;i< chart.series.length;i++)
                      chart.series[i].update({
                        pointWidth:MaximumBarWidth
                        });
                }
            }
        }
    

    http://jsfiddle.net/pXZRV/40/

    0 讨论(0)
  • 2021-02-18 14:53

    Obviously this question was asked a long time ago when this feature didn't exist, but as of Highcharts 4.1.8 you can do this without any workarounds using the plotOptions.column.maxPointWidth setting:

    $('#container').highcharts({
        /* Other chart settings here... */
        plotOptions: {
            column: {
                /* Here is the setting to limit the maximum column width. */
                maxPointWidth: 50
            }
        }
        /* Other chart settings here... */
    });
    

    Below is the JSFiddle of the basic column chart example, modified to show this working:

    http://jsfiddle.net/vu3dubhb/

    And the documentation for this setting is here: http://api.highcharts.com/highcharts#plotOptions.column.maxPointWidth

    0 讨论(0)
提交回复
热议问题