2 Replies Latest reply on Apr 22, 2010 8:12 AM by JulienJulien

    ColumnChart color depending on the value of the column




      I'va been trying for 2 days to change the colors of columnseries in a columnchart and it is actually awful. I've tried to do it inline without custom itemRenderer but I quickly understood that it is impossible. I then looked on the internet, and found that it was maybe possible by creating a custom itemRenderer class, extending ProgrammticSkin and implementing IdataRenderer.

      I have tried but am not at all able to retrieve the value of the column inside the itemRenderer. Even more, the so called _chartItem is always null and never never carries anything from anyparent.

      I'm a bit exhausted of trying and getting this value, so if you have some idea, i'll be very grateful.


      Here is the code for my itemRenderer class:



      import flash.display.Graphics;
          import flash.geom.Rectangle;
          import mx.charts.ChartItem;
          import mx.charts.chartClasses.GraphicsUtilities;
          import mx.charts.series.items.ColumnSeriesItem;
          import mx.controls.Alert;
          import mx.core.IDataRenderer;
          import mx.graphics.IFill;
          import mx.graphics.IStroke;
          import mx.skins.ProgrammaticSkin;


          public class ColorRenderer extends ProgrammaticSkin implements IDataRenderer
              public function ColorRenderer():void
              private var _chartItem:ChartItem;
              public function get data():Object
                  return _chartItem;
              public function set data(value:Object):void {
                  _chartItem = value as ColumnSeriesItem;


              private static const fills:Array = [0xFF0000,0x00FF00,0x0000FF,
              override protected function
                  updateDisplayList(unscaledWidth:Number,unscaledHeight:Number):void {
                  super.updateDisplayList(unscaledWidth, unscaledHeight);
                  var g:Graphics = graphics;
                  g.beginFill(fills[(_chartItem == null)? 0:_chartItem.element.y]);
                  g.drawRect(0, 0, unscaledWidth, unscaledHeight);
          } // Close class.
      } // Close package.





      Thank you