4

I have a graph which values on Y axis can quite vary. The only information I have is:

  • all values are integers
  • the value are >=0

Now if I have just few values with very low volatility like (lets take the extreme) [0,0,0,0,0,0,0] I got on my Y axis repetitive values. It looks like:

 |
1+
 |
1+
 |
1+
 |
0+
 |
0+
 |
0+-----------------------------------------

What I would like to achieve is to make jqPlot skip the repetitive values, possibly display only 2 ticks - 0,1 on the Y axis (the very bottom and very top one).

Any ideas? Adding my code for reference:

yaxis:{
    label:'Count',
    padMin: 0,
    labelRenderer: $.jqplot.CanvasAxisLabelRenderer,
    tickRenderer: $.jqplot.CanvasAxisTickRenderer,
    tickOptions:{
       formatString:'%d'
    }
}
Jan Zyka
  • 17,460
  • 16
  • 70
  • 118

5 Answers5

2

This is no bug at all. jqplot uses some kind of zoom in their graphics, so when you say formatString:'%d' you're forcing to show the int value in the y-axis. Deleting this line it will fall back to values like 1.3, 1.8, ... or so. I guess you want to show tickInterval of int values (I found this post seeking this same problem without response).

Guess this can't be done yet

Alwin Kesler
  • 1,450
  • 1
  • 20
  • 41
  • sorta is, I mean it should try to better handle this short coming than repeating the same number. – Eman Sep 13 '12 at 20:54
1

If you need to show only integer digits, you you may use custom string formatter:

 tickOptions:{
   formatString:'%d',
   formatter: yourCustomFormater
}

Where 'yourCustomFormatter' is enhanced default '$.jqplot.DefaultTickFormatter' :

var yourCustomFormatter = function (format, val) {
    if (typeof val == 'number') {
        if (!format) {
            format = $.jqplot.config.defaultTickFormatString;
        } 

        if (val % 1 === 0) {
            return $.jqplot.sprintf(format, val);
        } else {
            //ignore items with not integer values
            return '';
        }
    }
    else {
        return String(val);
    }
};

But be aware this formatter by default affects labels on your bar unless you use any other highlighter plugins.

Alex
  • 81
  • 1
  • 5
0

its a bug with the plugin, I can reproduce it on their demo code and I have the same problem myself.

for now set the chart to a smaller dimension as that's the current flaw with the plugin.

hope this helped.

Eman
  • 1,093
  • 2
  • 26
  • 49
0

you can use this

axes:{ xaxis:{ numberTicks: 2 } }

0

for me the below fixed the issue: 1- parameter tickOptions was tickOptions: {formatString: "%d"} I changed it to be tickOptions: {formatString: "%.2f"} because in case two elements rounded to the same integer value, its tick shows twice,

2- I've added extra parameter numberTicks: 4 to let axis has only 4 plots

with these two changes the current issue has been fixed but it may appears again according to the passed data to the graph

Ramy Feteha
  • 7,577
  • 1
  • 16
  • 10