-
Notifications
You must be signed in to change notification settings - Fork 12k
Description
Expected Behavior
maxTicksLimit should limit the number of ticks.
Current Behavior
maxTicksLimit doesn't limit the number of ticks. See https://jsfiddle.net/nagix/x68L9dw3/.
Possible Solution
Chart.js/src/scales/scale.linearbase.js
Line 27 in 2388eea
| spacing = helpers.niceNum(niceRange / (generationOptions.maxTicks - 1), true); |
true, and rounding the first argument in Chart.js/src/core/core.helpers.js
Lines 381 to 395 in 2388eea
| helpers.niceNum = function(range, round) { | |
| var exponent = Math.floor(helpers.log10(range)); | |
| var fraction = range / Math.pow(10, exponent); | |
| var niceFraction; | |
| if (round) { | |
| if (fraction < 1.5) { | |
| niceFraction = 1; | |
| } else if (fraction < 3) { | |
| niceFraction = 2; | |
| } else if (fraction < 7) { | |
| niceFraction = 5; | |
| } else { | |
| niceFraction = 10; | |
| } |
However, when setting the second argument to false, multiple tests failed as the generated ticks were changed. It seems to me that a whole logic for ticks generation needs to be improved because results are not consistent even if the number of ticks is below maxTicksLimit.
In particular, I don't understand why niceRange is used as the base for calculation at the first place.
Chart.js/src/scales/scale.linearbase.js
Line 26 in 2388eea
| niceRange = helpers.niceNum(dataRange.max - dataRange.min, false); |
Context
The same logic is used for a radialLinear scale, and this causes overlaps between tick labels in #5914.
Environment
- Chart.js version: 2.4.0 and later
- Browser name and version: All

