sunjavagroups / flot

Automatically exported from code.google.com/p/flot
MIT License
0 stars 0 forks source link

limit number of decimals on yaxis #554

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
For most of my graphs, flot calculates the y-axis values properly, but I have 
seen a few instances where the y values are low where the y axis values show a 
great number of decimals like the attached image.

I have tried using the tickDecimals as follows:

yaxis: {position: "left", color:"black", tickDecimals:2, tickColor:"black", 
tickFormatter: evaly},

but it doesnt do anything.

How can this be prevented?

Original issue reported on code.google.com by dqueve...@gmail.com on 17 Jun 2011 at 2:18

Attachments:

GoogleCodeExporter commented 8 years ago
Hi!

I think the problem here is your tickFormatter. Flot is rounding the float 
values, but when you change them to strings in your formatter, you're probably 
not doing anything special - and sometimes the values get rounded to something 
very close to, but not exactly a round decimal number (this is a somewhat 
surprising limitation of binary floating point numbers), which looks bad when 
converted.

I discovered the exact same problem inside Flot when I designed the rounding 
stuff, that's why the built-in number formatter is defined like this in the 
Flot source:

function (v, axis) {
    return v.toFixed(axis.tickDecimals);
}

And also why Flot goes to great lengths to try to compute a sensible value for 
tickDecimals, since it can't rely on the runtime to do the right thing. Hope 
this helps.

Original comment by olau%iol...@gtempaccount.com on 23 Jun 2011 at 7:07

GoogleCodeExporter commented 8 years ago
I had the same issue plotting big numbers, would write 3500000, 
3749999.99999999999, ...

fixed by adding a tickFormatter:

yaxis: {
                min: 3000000,
                autoscaleMargin: .5,
                tickFormatter: function suffixFormatter(val, axis) {
                    return (val.toFixed(0));
                }
            }

Original comment by aleck.la...@buildingenergy.com on 14 May 2012 at 3:35

GoogleCodeExporter commented 8 years ago

Original comment by dnsch...@gmail.com on 4 Jun 2012 at 2:52