diff --git a/src/core/core.scale.js b/src/core/core.scale.js index 1858078468c..68b3c1b1c9c 100644 --- a/src/core/core.scale.js +++ b/src/core/core.scale.js @@ -323,6 +323,10 @@ export default class Scale extends Element { } } + // Make sure min <= max when only min or max is defined by user and the data is outside that range + min = maxDefined && min > max ? max : min; + max = minDefined && min > max ? min : max; + return { min: finiteOrDefault(min, finiteOrDefault(max, min)), max: finiteOrDefault(max, finiteOrDefault(min, max)) diff --git a/test/specs/scale.linear.tests.js b/test/specs/scale.linear.tests.js index 9e8a61b6e6a..77a6dd5e4dd 100644 --- a/test/specs/scale.linear.tests.js +++ b/test/specs/scale.linear.tests.js @@ -51,6 +51,28 @@ describe('Linear Scale', function() { expect(chart.scales.y.max).toBe(150); }); + it('Should handle when only a min value is provided', () => { + var chart = window.acquireChart({ + type: 'line', + data: { + datasets: [{ + yAxisID: 'y', + data: [200] + }], + }, + options: { + scales: { + y: { + type: 'linear', + min: 250 + } + } + } + }); + + expect(chart.scales.y.min).toBe(250); + }); + it('Should handle when only a max value is provided', () => { var chart = window.acquireChart({ type: 'line',