c3js / c3

:bar_chart: A D3-based reusable chart library
http://c3js.org
MIT License
9.34k stars 1.39k forks source link

Handle floating point imprecision #797

Open jonashaag opened 9 years ago

jonashaag commented 9 years ago

C3 should take care of floating point rounding imprecision, i.e. values like "0.30000000000000004" (= 0.1 + 0.2), in X and Y axis ticks.

We could

Someone already reported this in #506, but no action was taken there to resolve the problem.

I think that this should be taken care of in c3, because it's a common problem (anyone dealing with floating point values is exposed to it).

masayuki0812 commented 9 years ago

How can we fix this?

mlajtos commented 9 years ago

Check out this D3 feature – nice. Maybe it can help.

dazhbog commented 9 years ago

I had the same issue but I fixed my data, I don't think the graphing library should take care of these things. It should just plot whatever you give it.

Unless you have a scenario that I have missed.

jcollum commented 8 years ago

I disagree. I'm getting some labels that are correct and some that are showing floating point problems:

image

It's not the data's fault, the data looks like:

{
  _id: "573a3743f6e91aa6b86a881d",
  status: "g",
  dt: 1463433027504,
  time: 2.8683171272278
},
{
_id: "573a374db23965e6eb42ca00",
status: "g",
dt: 1463433037064,
time: 2.8683171272278
},
{
_id: "573a375cb23965e6eb42ca14",
status: "g",
dt: 1463433052072,
time: 2.8683171272278
},
{
_id: "573a376bb23965e6eb42ca20",
status: "g",
dt: 1463433067104,
time: 2.4415690898895
},
{
_id: "573a377ab23965e6eb42ca36",
status: "g",
dt: 1463433082114,
time: 2.4415690898895
},
{
_id: "573a377ff6e91aa6b86a882f",
status: "g",
dt: 1463433087525,
time: 2.4415690898895
},
{
_id: "573a3789b23965e6eb42ca47",
status: "g",
dt: 1463433097093,
time: 2.4415690898895
},
jcollum commented 8 years ago

@masayuki0812 This looks like a bug to me, not an enhancement.

michaelrodov commented 8 years ago

hiw about adding default d3.format?

jcollum commented 8 years ago

I don't know if that will work, long-term, since the data coming in can vary a lot (sometimes it's decimal, sometimes it'll be integers).

jcollum commented 8 years ago

I set the y axis format to d3.format(".3n") and it seems to be helping. Hard to say though since the error doesn't show up very often.