mirror of
https://github.com/chartjs/Chart.js.git
synced 2025-12-08 20:36:08 +00:00
Logarithmic: handle null/NaN values (#8793)
This commit is contained in:
parent
6f6b1b2d17
commit
bd1df1bc34
@ -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);
|
||||
|
||||
49
test/fixtures/scale.logarithmic/null-values.js
vendored
Normal file
49
test/fixtures/scale.logarithmic/null-values.js
vendored
Normal file
@ -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',
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
BIN
test/fixtures/scale.logarithmic/null-values.png
vendored
Normal file
BIN
test/fixtures/scale.logarithmic/null-values.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 31 KiB |
@ -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);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user