Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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!

like image 706
unknown Avatar asked Nov 04 '11 01:11

unknown


3 Answers

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

Try this,

axesDefaults: 
{ 
    min: 0,  
    tickInterval: 1, 
    tickOptions: { 
            formatString: '%d' 
        } 
}
like image 62
Soulbe Avatar answered Oct 17 '22 01:10

Soulbe


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);
}
like image 37
Aurimas Neverauskas Avatar answered Oct 17 '22 01:10

Aurimas Neverauskas


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.

like image 27
Richard Housham Avatar answered Oct 17 '22 02:10

Richard Housham