-
Notifications
You must be signed in to change notification settings - Fork 11.9k
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
chart does not render if data contains value of 0 when using logarithmic scale #2966
Comments
@sibennayak, yes I do. That's why I'm reporting it. :) |
@barsh Can you tell us more about the scenario where you need to use a mathematically undefined number? Knowing the exact requirement might help us visualize the solution. |
@sibennayak it's possible that I'm misunderstanding the purpose of logarithmic scales. Here's the problem I'm trying to address. I'm showing a bar chart that displays the number of courses added each month. Some months, thousands of courses are imported (such is the case when we provision a new user). Most months, only a few courses are added. Some months, no courses are added. If one bar in the chart reflects that 10,000 courses were added and all the other bars reflect only a few courses were added, the slow months are all nearly zero-height. I was hoping to use logarithmic scales to emphasize the differences in the slow months. Here's an example where the slow months appear equal in height and zero-height: http://codepen.io/barsh/pen/xOYQWR I was hoping logarithmic scales would reveal that a few courses were imported Feb-Jun and none for July. |
There is no real way to handle 0 on a logarithmic scale. What you can do here increment all the values by 1 and then implement a custom tooltip function to show a actual values. Here's a fiddle https://jsfiddle.net/qz3vfu33/ |
Wouldn't it be better to allow user 0 values? I think we should consider this in calculations. |
@sibennayak thanks for the jsFiddle and suggesting increasing the data values by 1 and then showing a custom tooltip. That helped, but you were missing one key ingredient. It needs a custom yAxes too or all the values are off by one. Here's a fiddle that includes the custom yAxes: |
Thanks to @sibennayak I was able to get pretty close to something acceptable, but it just doesn't feel right... it shouldn't be this hacky. I had to increase all data values by 1, then customize the tooltips to decrement the data value and customize the y-axis to decrement the data value. Before(problem: Feb - July appear to be zero) After(problem: y-axis scale ends at 19,999 instead of 10,000) The problem that remains is this: incrementing the data values by 1, throws off the y-axis which should end at 10000 but ends at 19999 (see screenshot above). @roicos I'm all for a better solution if you can come up with one. |
@barsh Please, set 0 values to null like this data: [0.2, 100, null, 17000, 0.003] |
@roicos, using null instead of zero, helps but still in the chart below there was 1 vote in June and 0 votes in Jul, but you cannot deduce this from the looking at the chart. |
For anyone coming across this if you set the borderWidth to something other than 0 you will see a little bit of the bar for a small value not shown like June in this example. |
Thanks for your comment, I'll try to pay attention to it. |
This is an issue for me as well, and a lot of work for a workaround if editing custom tooltips and axes. For now I'm prepping the data with a function that replaces 0 with nulls |
- issue chartjs#3917: Logarithmic Scale Tick Bug for values of 0 - issue chartjs#4380: LogLog plots are impossible (0, 0) - issue chartjs#2966: chart does not render if data contains value of 0 when using logarithmic scale
Here we have one red vote, renders correctly:
Here we have zero red votes, does not render:
http://codepen.io/barsh/pen/GqOzKA
The text was updated successfully, but these errors were encountered: