Commits

Chris Leonello committed af78c25

Added support for stacked line (a.k.a. stacked area) charts. Note: stacked bar not implemented yet.

  • Participants
  • Parent commits 6d94d63

Comments (0)

Files changed (4)

File src/jqplot.core.js

         this._stack = false;
         this._stackData = [];
         this._plotData = [];
+        // data from the previous series, for stacked charts.
+        this._prevPlotData = [];
+        this._prevGridData = [];
         this._stackAxis = 'y';
         this.plugins = {};
     }
                     //this._stackData.push(this.series[i].data);
                     var temp = $.extend(true, [], this.series[i].data);
                     // create the data that will be plotted for this series
-                    var plotdata = $.extend(this, [], this.series[i].data);
+                    var plotdata = $.extend(true, [], this.series[i].data);
                     // for first series, nothing to add to stackData.
                     for (var j=0; j<i; j++) {
                         var cd = this.series[j].data;
                     this._plotData.push(this.series[i].data);
                     this.series[i]._plotData = this.series[i].data;
                 }
+                if (i>0) {
+                    this.series[i]._prevPlotData = this.series[i-1]._plotData;
+                }
             }
         };
         
         };
     
         this.draw = function(){
-            console.log(this);
             for (var i=0; i<$.jqplot.preDrawHooks.length; i++) {
                 $.jqplot.preDrawHooks[i].call(this);
             }

File src/jqplot.lineRenderer.js

         // recalculate the grid data
         var xp = this._xaxis.series_u2p;
         var yp = this._yaxis.series_u2p;
-        var gd = [];
-        var data = [];
+        var data = this._plotData;
+        var pdata = this._prevPlotData;
         this.gridData = [];
-        // if (this._stack) {
-        //     var sidx = this._stackAxis == 'x' ? 0 : 1;
-        //     var idx = s ? 0 : 1;
-        //     for (var i=0; i<this.data.length; i++) {
-        //         var temp = [];
-        //         temp[sidx] = this._stackData[i][sidx];
-        //         temp[idx] = this.data[i][idx];
-        //         data.push(temp);
-        //     }
-        // }
-        // else {
-        //     data = this.data;
-        // }
-        data = this._plotData;
-//        gd.push([xp.call(this._xaxis, data[0][0]), yp.call(this._yaxis, data[0][1])]); //????
         for (var i=0; i<this.data.length; i++) {
-            gd.push([xp.call(this._xaxis, data[i][0]), yp.call(this._yaxis, data[i][1])]);
+            this.gridData.push([xp.call(this._xaxis, data[i][0]), yp.call(this._yaxis, data[i][1])]);
+            if (pdata.length) {
+                this._prevGridData.push([xp.call(this._xaxis, pdata[i][0]), yp.call(this._yaxis, pdata[i][1])])
+            }
         }
-        this.gridData = gd;
     };
     
     // Method: makeGridData
         var xp = this._xaxis.series_u2p;
         var yp = this._yaxis.series_u2p;
         var gd = [];
-        // gd.push([xp.call(this._xaxis, data[0][0]), yp.call(this._yaxis, data[0][1])]);
+        var pgd = [];
         for (var i=0; i<data.length; i++) {
             gd.push([xp.call(this._xaxis, data[i][0]), yp.call(this._yaxis, data[i][1])]);
         }
         if (showLine) {
             // if we fill, we'll have to add points to close the curve.
             if (fill) {
-                var gridymin = this._yaxis.series_u2p(this._yaxis.min) - this.gridBorderWidth / 2;
-                // IE doesn't return new length on unshift
-                gd.unshift([gd[0][0], gridymin]);
-                len = gd.length;
-                gd.push([gd[len - 1][0], gridymin]);
+                // if not stacked, fill down to axis
+                if (this.index == 0 || !this._stack) {
+                    var gridymin = this._yaxis.series_u2p(this._yaxis.min) - this.gridBorderWidth / 2;
+                    // IE doesn't return new length on unshift
+                    gd.unshift([gd[0][0], gridymin]);
+                    len = gd.length;
+                    gd.push([gd[len - 1][0], gridymin]);                    
+                }
+                // if stacked, fill to line below 
+                else {
+                    var prev = this._prevGridData;
+                    for (var i=prev.length-1; i>-1; i--) {
+                        gd.push(prev[i]);
+                    }
+                }
             }
+            
             this.renderer.shapeRenderer.draw(ctx, gd, opts);                
 
             // now draw the shadows

File src/jqplot.linearAxisRenderer.js

         // the min/max bounds for this axis.
         for (var i=0; i<this._series.length; i++) {
             var s = this._series[i];
-            var d = s.data;
+            var d = s._plotData;
             
             for (var j=0; j<d.length; j++) { 
                 if (this.name == 'xaxis' || this.name == 'x2axis') {
 
 
     plot1 = $.jqplot('chart', [l1, l2], {
-        stackSeries: false,
+        stackSeries: true,
         grid:{background:'#fefbf3', borderWidth:2.5},
         seriesDefaults: {fill: true, showMarker: false, shadow: true},
         axes:{xaxis:{pad:1.0, numberTicks:5}},