If all values are integers, why are there floats in my y axis?

3,766 views
Skip to first unread message

Jonathan Prins

unread,
Aug 17, 2010, 6:43:06 PM8/17/10
to jqplot...@googlegroups.com
And is there any way to get rid of them?

e.g., if my data set is [[0,1].[1,2],[2,5],[3,9]] one of the ticks on the Y axis might end up being 5.7 or similar, which makes no sense. 

(decimals in the y axis don't make any sense whatsoever anyway - according to any graph standards, you should use whole numbers, scaling from 1,2,3 to 1,5,10 to 1,10,20 to 1,25,50 to 1,50,100 to 1,100,200, etc.. take a look)

Couldn't find anything in the docs about this.

Thanks,
Jon

valley

unread,
Aug 18, 2010, 3:14:45 AM8/18/10
to jqplot-users
Hi Jon,

you can use the 'formatString' parameter. For whole numbers on the
yAxis you would write

yaxis:{
tickOptions:{
formatString:'%.0f'
}
}

Regards
valley

Jonathan Prins

unread,
Aug 18, 2010, 4:00:24 AM8/18/10
to jqplot...@googlegroups.com

Wont my data points be misaligned, then?

E.g., the tick will be at 5.5 but read as 5; people might wonder why a data point that is 5 would show up below the "5" tick mark.

Sort of the same problem you see with dates on the y axis - the tick is labeled with a date, but a data point with that date will be completely misaligned by ~30 pixels. It just looks bad. And disengenuous.

> --
> You received this message because you are subscribed to the Google Groups "jqplot-users" group.
> To post to this group, send email to jqplot...@googlegroups.com.
> To unsubscribe from this group, send email to jqplot-users...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/jqplot-users?hl=en.
>

valley

unread,
Aug 20, 2010, 4:32:29 AM8/20/10
to jqplot-users
Well i hope that jqPlot will position the ticks correctly, depending
on the
format you've chosen.
Just write a little test where you format your y-Axis ticks with 2 and
0 decimal points
then you'll see the behaviour.
If it's incorrect then Chris probably can give you some hints on that.

Regards
valley


On 18 Aug., 10:00, Jonathan Prins <jonpr...@gmail.com> wrote:
> Wont my data points be misaligned, then?
>
> E.g., the tick will be at 5.5 but read as 5; people might wonder why a data
> point that is 5 would show up below the "5" tick mark.
>
> Sort of the same problem you see with dates on the y axis - the tick is
> labeled with a date, but a data point with that date will be completely
> misaligned by ~30 pixels. It just looks bad. And disengenuous.
>
> jqplot-users...@googlegroups.com<jqplot-users%2Bunsu...@googlegroups.com>
> .> For more options, visit this group at
>
> http://groups.google.com/group/jqplot-users?hl=en.
>
>

kimptoc

unread,
Sep 1, 2010, 8:20:38 AM9/1/10
to jqplot-users
Hi,

Works for me - thanks for the tip. Now need to see if there is a way
to do this with the DateAxisRenderer - getting strange times like 1
Aug 14:29, 5 Aug 14:18, 9 Aug 14:07 ...

Thanks,
Chris

Trond

unread,
Oct 14, 2010, 8:11:44 AM10/14/10
to jqplot-users


On Aug 18, 9:14 am, valley <rivell...@gmail.com> wrote:
> Hi Jon,
>
> you can use the 'formatString' parameter. For whole numbers on the
> yAxis you would write
>
>  yaxis:{
>           tickOptions:{
>             formatString:'%.0f'
>           }
>  }

I have tried this option as I have years on the X axis and integers on
the Y axis, but using the formatString:'%.0f' didn't change anything.

Chris Leonello

unread,
Oct 14, 2010, 6:18:10 PM10/14/10
to jqplot...@googlegroups.com
The format string only formats the display of a number, it does not change the actual value. That is, if a tick is at 23.456 with a format string of "%d", it will display as 23 on the plot but will still be positioned at 23.456. This may be what you are seeing.

The automatic tick generation algorithm is not optimal and should generate more "round" numbers. This in and of itself is not too difficult. It becomes very complex when you need to allow users to override any combination of axes min, max, tick interval, or number of ticks. The simplistic algorithm used in pre 1.0 versions to allow flexibility will be improved in later versions.


--
Chris Leonello
jqplot...@jqplot.com

> --
> You received this message because you are subscribed to the Google Groups "jqplot-users" group.
> To post to this group, send email to jqplot...@googlegroups.com.

> To unsubscribe from this group, send email to jqplot-users...@googlegroups.com.

Trond Husø

unread,
Oct 15, 2010, 4:51:56 AM10/15/10
to jqplot...@googlegroups.com
On Fri, Oct 15, 2010 at 12:18 AM, Chris Leonello <jqplot...@jqplot.com> wrote:
The format string only formats the display of a number, it does not change the actual value.  That is, if a tick is at 23.456 with a format string of "%d", it will display as 23 on the plot but will still be positioned at 23.456.  This may be what you are seeing.

stats = [[2000,55],[2001,44],[2002,84],[2003,70],[2004,99],[2005,37],[2006,18],[2007,14],[2008,17],[2009,32],[2010,15]];
plot = $.jqplot('chartdiv',[stats],
    {
    xaxis:{tickOptions:{formatString: '%d'}, min:2000, max:2011},
    yaxis:{tickOptions:{formatString: '%d'}, min:0, max:100},
    title:'Doping usage since 2000',
    series:[{color:'#5FAB78'}]
});
The code above gives the following output:
1999.0, 1999.9, 2000.8 on the x-axis and also floating numbers on the y axis. Is there some way I can fix this? I understand now that the '%d' stuff is ment for the plot, or is it?

Trond

 
Reply all
Reply to author
Forward
0 new messages