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
|
spacing = helpers.niceNum(niceRange / (generationOptions.maxTicks - 1), true); |
sets the second argument to
true, and rounding the first argument in
|
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; |
|
} |
causes the problem.
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.
|
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
Expected Behavior
maxTicksLimitshould limit the number of ticks.Current Behavior
maxTicksLimitdoesn'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
true, and rounding the first argument inChart.js/src/core/core.helpers.js
Lines 381 to 395 in 2388eea
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 belowmaxTicksLimit.In particular, I don't understand why
niceRangeis used as the base for calculation at the first place.Chart.js/src/scales/scale.linearbase.js
Line 26 in 2388eea
Context
The same logic is used for a radialLinear scale, and this causes overlaps between tick labels in #5914.
Environment