Chris Leonello avatar Chris Leonello committed 2a56239

Fixed issue #60 where seriesColors option was not working.

Comments (0)

Files changed (3)

src/jqplot.core.js

         // Group: methods
         //
         // method: init
-        // sets teh plot target, checks data and applies user
+        // sets the plot target, checks data and applies user
         // options to plot.
         this.init = function(target, data, options) {
             for (var i=0; i<$.jqplot.preInitHooks.length; i++) {
             }
             this.options = $.extend(true, {}, this.defaults, options);
             this.stackSeries = this.options.stackSeries;
+            if (this.options.seriesColors) {
+                this.seriesColors = this.options.seriesColors;
+            }
+            var cg = new this.colorGenerator(this.seriesColors);
             this._gridPadding = this.options.gridPadding;
             this.sortData = (this.options.sortData != null) ? this.options.sortData : this.sortData;
             for (var n in this.axes) {
 
                 // parse the renderer options and apply default colors if not provided
                 if (!temp.color && temp.show != false) {
-                    temp.color = this.getNextSeriesColor();
+                    temp.color = cg.next();
                 }
                 if (!temp.label) {
                     temp.label = 'Series '+ (i+1).toString();

src/plugins/jqplot.pieRenderer.js

             options.axesDefaults.renderer = $.jqplot.PieAxisRenderer;
             options.legend.renderer = $.jqplot.PieLegendRenderer;
             options.legend.preDraw = true;
-            options.seriesDefaults.colorGenerator = this.colorGenerator;
-            options.seriesDefaults.seriesColors = this.seriesColors;
+            // options.seriesDefaults.colorGenerator = this.colorGenerator;
+            // options.seriesDefaults.seriesColors = this.seriesColors;
+        }
+    }
+    
+    // called with scope of plot
+    function postParseOptions(options) {
+        for (var i=0; i<this.series.length; i++) {
+            this.series[i].seriesColors = this.seriesColors;
+            this.series[i].colorGenerator = this.colorGenerator;
         }
     }
     
     $.jqplot.preInitHooks.push(preInit);
+    $.jqplot.postParseOptionsHooks.push(postParseOptions);
     
     $.jqplot.PieTickRenderer = function() {
         $.jqplot.AxisTickRenderer.call(this);
 line2 = [3, 7, 2.5, 6, 5, 4];
 
 plot1 = $.jqplot('chart1', [line1], {
-  title: 'Default Pie Chart',
+  seriesColors:['#dd3333', '#d465f1', '#aa2211', '#3377aa', '#6699bb', '#9933aa'],
+  title: 'Default Pie Chart with Custom Colors',
   seriesDefaults:{renderer:$.jqplot.PieRenderer}
 });
 
   series:[{renderer:$.jqplot.PieRenderer, rendererOptions:{sliceMargin:8, fill:false, shadow:false, lineWidth:5}}], 
   legend:{show:true, location: 'w'}
 });
-
+ 
 plot3 = $.jqplot('chart4', [line2], {
   title: 'Not a Pie Chart that should render O.K. alongside a Pie Chart', 
+  seriesColors:['#dd3333', '#33dd33'],
   legend:{show:true, location: 'n'}
 });
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.