score:10

Accepted answer

i am amazed how difficult this is. not an optimal solution, but the best i can dream up with highchart's api:

var somedata = [1,5,82,9,300,5,42,199,5,6,99,1,56,52,250,64];

var chart = new highcharts.chart({

    chart: {
        renderto: 'container'
    },
    yaxis:{
        min: -10,
        tickinterval: 1,
        labels: {
            formatter: function() {
                if (this.value < somedata[0])
                    return null;
                else if (this.value == somedata[0])
                    return this.value;
                else if (this.value % 50 == 0)
                    return this.value;
            }
        }
    },
    series: [{
        data: somedata
    }]

});

enter image description here

score:3

a solution (that optimizes marks answer) is to use yaxis.labels.formatter with this.isfirst and this.axis.datamin, like this:

yaxis:{
    labels: {
        formatter: function() {
            if(this.isfirst)
                return this.axis.datamin;
            return this.value;
        }
    }
}

see this jsfiddle demo for an example.

the advantage of this is that you do not have to manually set tickinterval, which saves a lot of calls to formatter and lets highcharts figure out the label intervals itself. also, it uses the axis knowledge of the minimum data value, instead of having to check against an array (which you may have to iterate over to find the minimum).

beware that the yaxis.min must be set to something sensible here (works best with 0, and positive data). if the y-axis goes far below the minimum datapoint the first label will not be the one at 0.

the this.axis value was not available when this question was asked.


Related Query

More Query from same tag