Viji
Viji

Reputation: 61

Graph issue when y-axis has only '0' as values in highcharts

I have the following chart

http://jsfiddle.net/hcJjX/2/

If you notice the y-axis values are always '0' here. But the line is drawn in the middle of the chart. However, I want the line to be drawn on top of the 'x-axis' as follows (as it would be if there were atleast one non-zero value):

http://jsfiddle.net/hcJjX/2/

Is there something I am missing here?

Upvotes: 1

Views: 2812

Answers (3)

Nike
Nike

Reputation: 25

Here, column with type date time values. So, please go with "null" instead of 0.

Like given below,

series: [{
data: [[1373308338468,null],[1373308938471,null]]
}]

But workaround at yAxis by minRange to "0.01"

Example,

yAxis: { min: 0, minRange: 0.01 }

Upvotes: 0

SteveP
SteveP

Reputation: 19093

The chart is unable to calculate a sensible y-axis scale as it has no min/max values to go on. If you tell it a max, then it renders as you want:

 yAxis: {
    endOnTick: false,
    minPadding: 0,
    max:1
},

If you don't want to iterate through your data to work out if all the points are zero, let highcharts do the work for you as it has to calculate the min/max anyway. You can call getExtremes to work out the max y value, and use setExtremes to force a particular max:

chart: {
        plotBorderWidth: 1,
        type: 'column',
        events: {
            load: function (event) {
                var extremes = this.yAxis[0].getExtremes();
                if (extremes.dataMax == 0) {
                    extremes.max = 1;
                    this.yAxis[0].setExtremes(0, 1);
                }
            }
        }
    },

http://jsfiddle.net/CbwrB/

Upvotes: 3

Strikers
Strikers

Reputation: 4776

if you wan to see the graph even when the value is zero you can go with

plotOptions: {
 series: {
   minPointLength: 3
 }
},

here is your updated fiddle http://jsfiddle.net/hcJjX/4/

Hope this will be of use

Upvotes: -1

Related Questions