mirror of
https://github.com/chartjs/Chart.js.git
synced 2026-03-13 11:46:55 +01:00
Scale min/max calculations now disregard bad values
This commit is contained in:
@@ -25,6 +25,9 @@
|
||||
helpers.each(dataset.data, function(rawValue, index) {
|
||||
|
||||
var value = this.getRightValue(rawValue);
|
||||
if (isNaN(value)) {
|
||||
return;
|
||||
}
|
||||
|
||||
positiveValues[index] = positiveValues[index] || 0;
|
||||
negativeValues[index] = negativeValues[index] || 0;
|
||||
@@ -51,6 +54,9 @@
|
||||
if (helpers.isDatasetVisible(dataset) && (this.isHorizontal() ? dataset.xAxisID === this.id : dataset.yAxisID === this.id)) {
|
||||
helpers.each(dataset.data, function(rawValue, index) {
|
||||
var value = this.getRightValue(rawValue);
|
||||
if (isNaN(value)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.min === null) {
|
||||
this.min = value;
|
||||
@@ -155,17 +161,18 @@
|
||||
getPixelForValue: function(value, index, datasetIndex, includeOffset) {
|
||||
// This must be called after fit has been run so that
|
||||
// this.left, this.top, this.right, and this.bottom have been defined
|
||||
var rightValue = this.getRightValue(value);
|
||||
var pixel;
|
||||
var range = this.end - this.start;
|
||||
|
||||
if (this.isHorizontal()) {
|
||||
|
||||
var innerWidth = this.width - (this.paddingLeft + this.paddingRight);
|
||||
pixel = this.left + (innerWidth / range * (this.getRightValue(value) - this.start));
|
||||
pixel = this.left + (innerWidth / range * (rightValue - this.start));
|
||||
return Math.round(pixel + this.paddingLeft);
|
||||
} else {
|
||||
var innerHeight = this.height - (this.paddingTop + this.paddingBottom);
|
||||
pixel = (this.bottom - this.paddingBottom) - (innerHeight / range * (this.getRightValue(value) - this.start));
|
||||
pixel = (this.bottom - this.paddingBottom) - (innerHeight / range * (rightValue - this.start));
|
||||
return Math.round(pixel);
|
||||
}
|
||||
},
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
var remain = value / (Math.pow(10, Math.floor(Chart.helpers.log10(value))));
|
||||
|
||||
if (remain === 1 || remain === 2 || remain === 5) {
|
||||
return value.toExponential()
|
||||
return value.toExponential();
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
@@ -38,6 +38,9 @@
|
||||
helpers.each(dataset.data, function(rawValue, index) {
|
||||
|
||||
var value = this.getRightValue(rawValue);
|
||||
if (isNaN(value)) {
|
||||
return;
|
||||
}
|
||||
|
||||
values[index] = values[index] || 0;
|
||||
|
||||
@@ -59,6 +62,9 @@
|
||||
if (helpers.isDatasetVisible(dataset) && (this.isHorizontal() ? dataset.xAxisID === this.id : dataset.yAxisID === this.id)) {
|
||||
helpers.each(dataset.data, function(rawValue, index) {
|
||||
var value = this.getRightValue(rawValue);
|
||||
if (isNaN(value)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.min === null) {
|
||||
this.min = value;
|
||||
|
||||
@@ -69,8 +69,11 @@
|
||||
|
||||
helpers.each(this.data.datasets, function(dataset) {
|
||||
if (helpers.isDatasetVisible(dataset)) {
|
||||
helpers.each(dataset.data, function(value, index) {
|
||||
if (value === null) return;
|
||||
helpers.each(dataset.data, function(rawValue, index) {
|
||||
var value = this.getRightValue(rawValue);
|
||||
if (isNaN(value)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.min === null) {
|
||||
this.min = value;
|
||||
|
||||
Reference in New Issue
Block a user