how to display y-axis value to integers only in jqplot

10,076

Solution 1

if i understand what you want, is to display in y axis integer values.

Try this,

axesDefaults: 
{ 
    min: 0,  
    tickInterval: 1, 
    tickOptions: { 
            formatString: '%d' 
        } 
}

Solution 2

Override createTicks function and introduce new axis bool property - integersOnly.

// jqplot adding integersOnly option for an axis
var oldCreateTicks = $.jqplot.LinearAxisRenderer.prototype.createTicks;
$.jqplot.LinearAxisRenderer.prototype.createTicks = function (plot) {
    if (this.integersOnly == true) {
        var db = this._dataBounds;
        var min = ((this.min != null) ? this.min : db.min);
        var max = ((this.max != null) ? this.max : db.max);
        var range = max - min;
        if (range < 3) {
            if (this.min == null) {
                this.min = 0;
            }
            this.tickInterval = 1;
        }
    }
    return oldCreateTicks.apply(this, plot);
}

Solution 3

Just to build on the top answer.

axes: {
         yaxis: {
             min: 0,
             tickInterval: 1, 
             tickOptions: {
                  formatString: '%d'
             }

          }
       }

Would just apply this to the yaxis. Helpful, if you have a bar chart or some other chart and you want to isolate the axis.

Share:
10,076
unknown
Author by

unknown

Updated on June 24, 2022

Comments

  • unknown
    unknown almost 2 years

    How do i make the value of y-axis into integer?

    i currently have this value 0.0 1.0 1.5 2.0 2.5 3.0. i want to change it to some thing like this 0 1 2 3 etc....

    thank you! cheers!