David McIntyre
David McIntyre

Reputation: 74

Highcharts: bar/column chart label position with values of 0

If I have a Highcharts bar or column chart that has a data series with an array of all zeroes, the y axis tick label displays in the center of the y axis, along with an extra y axis. I've experimented with the tick placement and min values but these dont seem to work in the case of this peculiar set of data. see http://jsfiddle.net/davidpmcintyre/mepd17tn/

Here's the highcharts code snippet:

$(function () {
    $('#container').highcharts({
        chart: {
            type: 'bar'
        },
        xAxis: {
            categories: ['Jan', 'Feb', 'Mar', 'Apr' ]
        },      

        series: [{
            data: [0, 0, 0, 0]
        }]
    });
});

Upvotes: 1

Views: 1260

Answers (1)

Halvor Holsten Strand
Halvor Holsten Strand

Reputation: 20536

Assuming (given requirements of your chart):

  • All data will be positive
  • You always want to start from 0 on the y-axis

The following code will allow you to left-align your y-axis, and also specify how much of the y-axis you want to show in minimal cases (JSFiddle):

yAxis: {
    min: 0,
    minRange: 1
}

This will still allow you to have larger ranges on the y-axis as it only kicks in when the value range is less than one. This in turn means you do not have to check your data before setting any values.

Upvotes: 0

Related Questions