-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Wish to have yaxis 0 tick always showing, but forceNiceScale does not seem to work properly with min/max values -1 < value < 1 #4283
Comments
By setting max: 0.11 and min: -0.1, you set the range (0.21), and this must be divided into even spacings. So you get either 7 divisions of 0.03 (most likely) or 3 divisions of 0.07 (unlikely), and neither of those land on zero. You could try the following: max: 0.12, max: 0.12, PS. This is not a bug. The documentation needs to be updated but even in it's current form doesn't imply that it will guarantee a zero tick. As of 3.46.0, user options are honored if self-consistent but an option will be tweaked or ignored if it's in conflict with other user-defined options. Min and/or max are always honored, then stepSize and tickAmount, in roughly that order of priority. For example, setting min: 0, max: 10 and stepSize: 3 is in conflict, so stepSize would be tweaked to fit. ForceNiceScale is used to choose between various alternative outcomes under certain conditions. |
@rosco54 Thanks a lot for your quick answer! These infos will sure help me out a lot trying to figure this out. I tried tweaking my code a little bit more and noticed that even when nor min or max are passed, some of my charts with small values still don't land on 0. Do you think it would be a nice feature to have some way of forcing the 0 to show up? I think it would make some charts a lot easier to read. In this case i misstagged my issue and I apologize, it should have been a feature request. But still, do you think that would be possible? I think it would be a lot more friendly if that existed instead of having to add extra complexity on my code to do these kinds of maths to have a chance that it might land on 0 |
Yes, it would be nice, and the unrestricted auto scaling generally does that. Indirectly though, as a side effect of how it does the scaling, so it's not 100% guaranteed even when no user-defined options are present. The solution in that case, may be to increase the margin space on the chart area so that you don't have to try to make allowance for it using min or max settings. |
@ehbats Would you be able to add one of those "charts with small values [that] still don't land on 0" to this issue? One of those that don't include min or max. I would like to see how that is happening and I can't seem to conjure up an example of my own that doesn't land on zero. |
Description
Hello guys,
I am currently facing a problem where I can't force my chart to always have the 0 tick on the y-axis. I can't set my min to 0 because my series has negative values. I tried using forceNiceScale but it does not seem to solve my problem when i pass custom min/max values. With custom min/max values (that are -1 < value < 1) the 0 tick behavior looks random and I haven't found a way to consistenly make the 0 tick appear. I tried taking a look at #1771 but using annotation does not really solve my problem, and my problem is not solved by the OP's solution probably because of my very small values series.
Steps to Reproduce
Expected Behavior
Consistent yaxis always showing the 0 tick when passing min/max values and forceNiceScale
Actual Behavior
Yaxis seems to randomly show the 0 tick when I pass min/max values that are 0 < value < 1
Screenshots
Yaxis 0 tick not showing when i pass small min/max values:
Without the min/max values the 0 tick shows up, but my datalabels formatting on the -0.08% series value gets messy:
Reproduction Link
This codepen shows how the chart does not properly show the y-axis 0 tick when I pass min/max values that are 0 < value < 1:
https://codepen.io/Eduardo-Batistella/pen/xxexqOQ
You may change the values of min/max and see how the yaxis ticks behavior looks a bit random with such small values.
This other codepen shows how the chart (apparently) correctly formats the y axis with the 0 tick when i do not pass min/max values:
https://codepen.io/Eduardo-Batistella/pen/xxexqYe
However, this is not good enough for me as it messes with my dataLabels formatting on the -0.08% value. The bar hits the limit of the y-axis and my label undesirely goes inside the bar.
Can you guys help me fix this problem please? I've been trying to fix it for a while now and haven't found a solution
The text was updated successfully, but these errors were encountered: