diff --git a/src/scales/scale.category.js b/src/scales/scale.category.js index 3d773a8a8c2..5565abc3f72 100644 --- a/src/scales/scale.category.js +++ b/src/scales/scale.category.js @@ -25,7 +25,7 @@ const validIndex = (index, max) => index === null ? null : _limitValue(Math.roun function _getLabelForValue(value) { const labels = this.getLabels(); - if (value >= 0 && value < labels.length) { + if (typeof value === 'number' && value >= 0 && value < labels.length) { return labels[value]; } return value; diff --git a/test/specs/scale.category.tests.js b/test/specs/scale.category.tests.js index 70b0bb9a383..03d77f6af8f 100644 --- a/test/specs/scale.category.tests.js +++ b/test/specs/scale.category.tests.js @@ -158,7 +158,7 @@ describe('Category scale tests', function() { yAxisID: 'y', data: [10, 5, 0, 25, 78] }], - labels: ['tick1', 'tick2', 'tick3', 'tick4', 'tick5'] + labels: ['tick1', 'tick2', 'tick3', '1', 'tick5'] }, options: { scales: { @@ -176,6 +176,8 @@ describe('Category scale tests', function() { var scale = chart.scales.x; expect(scale.getLabelForValue(1)).toBe('tick2'); + expect(scale.getLabelForValue('tick3')).toBe('tick3'); + expect(scale.getLabelForValue('1')).toBe('1'); // and not 'tick2' }); it('Should get the correct pixel for a value when horizontal', function() {