]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Fix linear scale stacked mode
authorEvert Timberg <evert.timberg@gmail.com>
Sun, 24 Jan 2016 14:22:28 +0000 (09:22 -0500)
committerEvert Timberg <evert.timberg@gmail.com>
Sun, 24 Jan 2016 14:22:28 +0000 (09:22 -0500)
src/scales/scale.linear.js

index 01393d76bdaf0690d8abbe2563d3a013a2caf819..8c27785094516bef269f8e966b374c8c965f74ed 100644 (file)
@@ -43,6 +43,7 @@
 
                        if (this.options.stacked) {
                                var valuesPerType = {};
+                               var hasPositiveValues = false;
                                var hasNegativeValues = false;
 
                                helpers.each(this.chart.data.datasets, function(dataset) {
@@ -75,6 +76,7 @@
                                                                        hasNegativeValues = true;
                                                                        negativeValues[index] += value;
                                                                } else {
+                                                                       hasPositiveValues = true;
                                                                        positiveValues[index] += value;
                                                                }
                                                        }
@@ -83,7 +85,7 @@
                                }, this);
 
                                helpers.each(valuesPerType, function(valuesForType) {
-                                       var values = hasNegativeValues ? valuesForType.positiveValues.concat(valuesForType.negativeValues) : valuesForType.positiveValues;
+                                       var values = hasPositiveValues ? hasNegativeValues ? valuesForType.positiveValues.concat(valuesForType.negativeValues) : valuesForType.positiveValues : valuesForType.negativeValues;
                                        var minVal = helpers.min(values);
                                        var maxVal = helpers.max(values)
                                        this.min = this.min === null ? minVal : Math.min(this.min, minVal);