Highcharts - Why is there extra spacing before the

2019-02-19 23:01发布

问题:

I have a Highcharts datetime column chart, with several series that which are added and updated dynamically. It appears that the library is producing the chart with a large chunk of space before the first column and after the last column. It's as if the columns are grouped into the center of the chart, while they should be arranged evenly across the space. I have tried adjusting the minPadding and maxPadding of the axis options with no success:

    xAxis: {
        type: 'datetime',
        minPadding: 0,
        maxPadding: 0,
        labels:{
            formatter:function () {
                return Highcharts.dateFormat('%b %e', this.value);
            }
        }
    },

Here is an example adapted from the Highcharts demo page which is behaving correctly:

http://jsfiddle.net/ricksuggs/8Gt2y/

While this example which is written by myself, is showing the extra padding:

http://jsfiddle.net/ricksuggs/PRKAJ/36/

Thank you.

回答1:

You can modify pointWidth and groupPadding/pointPadding parameter

http://jsfiddle.net/PRKAJ/37/

EDIT: You should define pointRange

http://jsfiddle.net/PRKAJ/41/

http://api.highcharts.com/highcharts#plotOptions.series.pointRange



回答2:

From what I'm seeing, example http://jsfiddle.net/ricksuggs/PRKAJ/36/ is showing to me without extra padding; unlike on the screenshot by @ricksuggs above, where there is extra padding.

I believe the "problem" lies within multiple series with single data points vs. a single series with multiple data points.

With multiple series (=sets) with single data point in each set, columns are grouped together, expecting another grouped data points from another set, thus creating the padding. However, with a single set containing multiple data points, those are distributed evenly creating no additional padding.

To answer your question, I believe that's why there is extra spacing. However, I could not find a way how to get rid of it as grouping multiple series into single set with multiple data points has other limitations (hiding series in legend, coloring, ...).