Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(bar) Values between 0 and 1 being shown as 100m, 200m, etc #89

Closed
bolemeus opened this issue Jun 27, 2014 · 4 comments
Closed

(bar) Values between 0 and 1 being shown as 100m, 200m, etc #89

bolemeus opened this issue Jun 27, 2014 · 4 comments
Labels

Comments

@bolemeus
Copy link

I've put a bar chart on my site, and I've noticed that the values between 0 and 1 are being shown as 100m, 200m, etc.

Not only is this incorrect (I believe the m stands for million), but it also doesn't fit in the container. The first number is being clipped, making the chart show 00m at each tick between 0 and 1.

barchart

@bolemeus bolemeus changed the title Values between 0 and 1 being shown as 100m, 200m, etc (bar) Values between 0 and 1 being shown as 100m, 200m, etc Jun 27, 2014
@chinmaymk
Copy link
Owner

Yup this is definitely a bug, could you reproduce this on plunkr ? Will be easier to debug.

@chinmaymk chinmaymk added the bug label Jun 30, 2014
@bolemeus
Copy link
Author

Hey chinmaymk,

This actually works as expected. The formatting of numbers is by the SI-prefix in your code. This means all numbers are formatted to a number between zero and 999, and appends it with the correct multiplier. In this case the number is appended with an m, which stands for milli (* 0,001)

One could argue whether you want this kind of behaviour or not. It certainly is correct, but in my case it is not preferred.

You could fix this by changing the type of formatting, but I think it would be better to make it configurable. I made some changes to show fewer ticks when the max Y value is smaller than 10.

For now I add a variable to the barchart in which I store the maximum Y value. If this value is less than 10, then I set the number of ticks to that value. This way I never get values between zero and 1.

I tried reproducing this in your example on plunkr, but there the numbers between zero and 1 are being shown as 0.1, 0.2, 0.3, etc...

It seems the last number to be shown like that is 0.009 (9m)

Maybe this is because of the version of d3 I use...? I don't know.

Ok, I just checked it and appearantly the latest version of d3 (3.4.8) formats numbers like 1m, 10m, 100m, 1, etc, while the version of d3 that your plunkr uses (3.3.11) only formats numbers like, 1m, 0.01, 0.1, 1

@bolemeus
Copy link
Author

forgot my own plunkr...

http://plnkr.co/edit/zTCimJ1VsRltFOoroOJk?p=preview

@chinmaymk
Copy link
Owner

😊 I guess we can add a hook for tickFormat from config object. Trick is it has to work for all types of charts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants