diff --git a/src/scales/scale.linearbase.js b/src/scales/scale.linearbase.js index d2da5501eb7..5fd536efd54 100644 --- a/src/scales/scale.linearbase.js +++ b/src/scales/scale.linearbase.js @@ -138,7 +138,11 @@ function generateTicks(generationOptions, dataRange) { ticks.push({value: max}); } } else if (!maxDefined || niceMax === max) { - ticks.push({value: niceMax}); + // Avoid duplicating the last emitted tick when the rounded niceMax + // coincides with it (e.g. bounds: 'data' with a fractional data max). + if (!ticks.length || ticks[ticks.length - 1].value !== niceMax) { + ticks.push({value: niceMax}); + } } return ticks; diff --git a/test/specs/scale.linear.tests.js b/test/specs/scale.linear.tests.js index a8ad53995b1..007ee5d3828 100644 --- a/test/specs/scale.linear.tests.js +++ b/test/specs/scale.linear.tests.js @@ -967,6 +967,31 @@ describe('Linear Scale', function() { expect(chart.scales.y.max).toEqual(99); }); + it('Should not produce a duplicate final tick when bounding to a fractional data max', function() { + var chart = window.acquireChart({ + type: 'line', + data: { + labels: ['a', 'b'], + datasets: [{ + data: [0, 5.4] + }] + }, + options: { + scales: { + y: { + type: 'linear', + bounds: 'data', + ticks: { + autoSkip: false + } + } + } + } + }); + + expect(getLabels(chart.scales.y)).toEqual(['0', '1', '2', '3', '4', '5']); + }); + it('Should build labels using the user supplied callback', function() { var chart = window.acquireChart({ type: 'bar',