diff --git a/src/scales/scale.logarithmic.js b/src/scales/scale.logarithmic.js index 2223f1cff88..99e83241485 100644 --- a/src/scales/scale.logarithmic.js +++ b/src/scales/scale.logarithmic.js @@ -170,6 +170,9 @@ export default class LogarithmicScale extends Scale { if (value === undefined || value === 0) { value = me.min; } + if (value === null || isNaN(value)) { + return NaN; + } return me.getPixelForDecimal(value === me.min ? 0 : (log10(value) - me._startValue) / me._valueRange); diff --git a/test/fixtures/scale.logarithmic/null-values.js b/test/fixtures/scale.logarithmic/null-values.js new file mode 100644 index 00000000000..a9450f0d623 --- /dev/null +++ b/test/fixtures/scale.logarithmic/null-values.js @@ -0,0 +1,49 @@ +module.exports = { + config: { + type: 'line', + data: { + labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July'], + datasets: [{ + backgroundColor: 'red', + borderColor: 'red', + fill: false, + data: [ + 150, + null, + 1500, + 200, + 9000, + 3000, + 8888 + ], + spanGaps: true + }, { + backgroundColor: 'blue', + borderColor: 'blue', + fill: false, + data: [ + 1000, + 5500, + 800, + 7777, + null, + 6666, + 5555 + ], + spanGaps: false + }] + }, + options: { + responsive: true, + scales: { + x: { + display: false, + }, + y: { + display: false, + type: 'logarithmic', + } + } + } + } +}; diff --git a/test/fixtures/scale.logarithmic/null-values.png b/test/fixtures/scale.logarithmic/null-values.png new file mode 100644 index 00000000000..d75929610c1 Binary files /dev/null and b/test/fixtures/scale.logarithmic/null-values.png differ diff --git a/test/specs/scale.logarithmic.tests.js b/test/specs/scale.logarithmic.tests.js index 221152b66b5..b68ef305e6d 100644 --- a/test/specs/scale.logarithmic.tests.js +++ b/test/specs/scale.logarithmic.tests.js @@ -3,6 +3,8 @@ function getLabels(scale) { } describe('Logarithmic Scale tests', function() { + describe('auto', jasmine.fixture.specs('scale.logarithmic')); + it('should register', function() { var Constructor = Chart.registry.getScale('logarithmic'); expect(Constructor).not.toBe(undefined);