]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Create null value bars, and hide if not numeric
authorNick Downie <hello@nickdownie.com>
Tue, 8 Jul 2014 21:27:39 +0000 (22:27 +0100)
committerNick Downie <hello@nickdownie.com>
Tue, 8 Jul 2014 21:27:39 +0000 (22:27 +0100)
src/Chart.Bar.js

index aca50d82f3ed53eed92a6e635817f1d4a51c6d5a..0f29a3df53276719486d5a30299360ec3db858ee 100644 (file)
                                this.datasets.push(datasetObject);
 
                                helpers.each(dataset.data,function(dataPoint,index){
-                                       if (helpers.isNumber(dataPoint)){
-                                               //Add a new point for each piece of data, passing any required data to draw.
-                                               datasetObject.bars.push(new this.BarClass({
-                                                       value : dataPoint,
-                                                       label : data.labels[index],
-                                                       datasetLabel: dataset.label,
-                                                       strokeColor : dataset.strokeColor,
-                                                       fillColor : dataset.fillColor,
-                                                       highlightFill : dataset.highlightFill || dataset.fillColor,
-                                                       highlightStroke : dataset.highlightStroke || dataset.strokeColor
-                                               }));
-                                       }
+                                       //Add a new point for each piece of data, passing any required data to draw.
+                                       datasetObject.bars.push(new this.BarClass({
+                                               value : dataPoint,
+                                               label : data.labels[index],
+                                               datasetLabel: dataset.label,
+                                               strokeColor : dataset.strokeColor,
+                                               fillColor : dataset.fillColor,
+                                               highlightFill : dataset.highlightFill || dataset.fillColor,
+                                               highlightStroke : dataset.highlightStroke || dataset.strokeColor
+                                       }));
                                },this);
 
                        },this);
                addData : function(valuesArray,label){
                        //Map the values array for each of the datasets
                        helpers.each(valuesArray,function(value,datasetIndex){
-                                       if (helpers.isNumber(value)){
-                                               //Add a new point for each piece of data, passing any required data to draw.
-                                               this.datasets[datasetIndex].bars.push(new this.BarClass({
-                                                       value : value,
-                                                       label : label,
-                                                       x: this.scale.calculateBarX(this.datasets.length, datasetIndex, this.scale.valuesCount+1),
-                                                       y: this.scale.endPoint,
-                                                       width : this.scale.calculateBarWidth(this.datasets.length),
-                                                       base : this.scale.endPoint,
-                                                       strokeColor : this.datasets[datasetIndex].strokeColor,
-                                                       fillColor : this.datasets[datasetIndex].fillColor
-                                               }));
-                                       }
+                               //Add a new point for each piece of data, passing any required data to draw.
+                               this.datasets[datasetIndex].bars.push(new this.BarClass({
+                                       value : value,
+                                       label : label,
+                                       x: this.scale.calculateBarX(this.datasets.length, datasetIndex, this.scale.valuesCount+1),
+                                       y: this.scale.endPoint,
+                                       width : this.scale.calculateBarWidth(this.datasets.length),
+                                       base : this.scale.endPoint,
+                                       strokeColor : this.datasets[datasetIndex].strokeColor,
+                                       fillColor : this.datasets[datasetIndex].fillColor
+                               }));
                        },this);
 
                        this.scale.addXLabel(label);
                        //Draw all the bars for each dataset
                        helpers.each(this.datasets,function(dataset,datasetIndex){
                                helpers.each(dataset.bars,function(bar,index){
-                                       bar.base = this.scale.endPoint;
-                                       //Transition then draw
-                                       bar.transition({
-                                               x : this.scale.calculateBarX(this.datasets.length, datasetIndex, index),
-                                               y : this.scale.calculateY(bar.value),
-                                               width : this.scale.calculateBarWidth(this.datasets.length)
-                                       }, easingDecimal).draw();
+                                       if (helpers.isNumber(bar.value)){
+                                               bar.base = this.scale.endPoint;
+                                               //Transition then draw
+                                               bar.transition({
+                                                       x : this.scale.calculateBarX(this.datasets.length, datasetIndex, index),
+                                                       y : this.scale.calculateY(bar.value),
+                                                       width : this.scale.calculateBarWidth(this.datasets.length)
+                                               }, easingDecimal).draw();
+                                       }
                                },this);
 
                        },this);