how to display y-axis value to integers only in jqplot
Asked Answered
E

4

9

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!

Evildoer answered 4/11, 2011 at 1:51 Comment(0)
D
28

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

Try this,

axesDefaults: 
{ 
    min: 0,  
    tickInterval: 1, 
    tickOptions: { 
            formatString: '%d' 
        } 
}
Daube answered 21/8, 2012 at 10:35 Comment(2)
I used just the "tickOptions: formatString: '%d'", and it worked great.Merissa
but for max 1 pt on y axis, it shows o,1,1 on yaxisApocrypha
O
1

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);
}
Olympic answered 24/11, 2015 at 15:3 Comment(0)
S
1

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.

Spinning answered 16/12, 2016 at 10:11 Comment(0)
S
-4

Try parseInt(y_axis)

(filler text, answer too short)

Spooner answered 4/8, 2012 at 6:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.