覆盖flex烛台图表itemrenderer

时间:2013-06-24 18:00:51

标签: actionscript-3 flex charts mxml

我试图覆盖烛台图表项目渲染器但不能在我自己的基础上发布基类渲染

来自flex api帮助:

itemRenderer
Type: mx.core.IFactory CSS Inheritance: No
Language Version: ActionScript 3.0  Product Version: Flex 3  Runtime Versions: Flash9, AIR 1.1 

A factory that represents the class the series will use to represent individual items on the chart. This class is instantiated once for each element in the chart. Classes used as an itemRenderer should implement the IFlexDisplayObject, ISimpleStyleClient, and IDataRenderer interfaces. The data property is assigned the chartItem that the skin instance renders.

作为自定义渲染器的文件声明:

package { // Empty package.

  import mx.charts.series.items.HLOCSeriesItem;
  import mx.core.IDataRenderer;
  import mx.core.IFlexDisplayObject;
  import mx.styles.ISimpleStyleClient;
  import flash.display.Graphics;
  import mx.charts.chartClasses.HLOCSeriesBase;
  import mx.charts.series.CandlestickSeries;

  public class CycleColorRenderer extends HLOCSeriesBase 

     implements IFlexDisplayObject, ISimpleStyleClient, IDataRenderer {

     private var colors:Array = [0xCCCC99,0x999933,0x999966];
     private var _chartItem:HLOCSeriesItem;

     public function CycleColorRenderer() {
        super();
     }

     public function get data():Object {
        return _chartItem;
     }

     public function set data(value:Object):void {
        _chartItem = value as HLOCSeriesItem; 
        invalidateDisplayList();
     }

     override protected function
        updateDisplayList(unscaledWidth:Number,unscaledHeight:Number):void {
           super.updateDisplayList(unscaledWidth, unscaledHeight);
/*           var g:Graphics = graphics;

           g.clear();  
           g.beginFill(colors[(_chartItem == null)? 0:0]);
           g.drawRect(0, 0, unscaledWidth, unscaledHeight);
           g.endFill();
*/      
/*         
           if( _chartItem && _chartItem.index == 0) {
            g.beginFill(0xFF0000); // Red line, you can select your own color
            // Draw the line across the chart. This is actually a rectangle with height 1.
            g.drawRect(-50,0,this.parent.width+50, 1);
            g.endFill();
           }
*/         
     }
  } // Close class.
} // Close package.

mxml声明:

<mx:CandlestickSeries
    dataProvider="{TICKER}"
    openField="open"
    highField="high"
    lowField="low"
    closeField="close"
    displayName="TICKER"
    itemRenderer="CycleColorRenderer"
    >

正在渲染图表,但是代替默认蜡烛会在它们的位置无效,但是我可以检索条形属性并自我渲染 - 我只想从基类发出基本渲染器并且只是在顶部绘制它的。我错过了什么?

0 个答案:

没有答案