1

目前我已经创建了下面的类,它扩展了 ItemRenderer 来为折线图中的所有数据点添加标签。

package lib

{
    public class LineChartLabelRenderer extends UIComponent implements IDataRenderer, IFactory

    {

        private var _label:Label;

        public var solidColor:SolidColor;

        public function newInstance():*
        {
            return new LineChartLabelRenderer();
        }
        public function LineChartLabelRenderer():void

        {
            super();
            _label = new Label();
            addChild(_label);
            _label.setStyle("color",0x000000);
            _label.setStyle("fontSize",9);
        }

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

        public function set data(value:Object):void

        {
            if (_chartItem == value){
                return;
            }
            _chartItem = ChartItem(value);
            if(_chartItem != null){
                _label.text = LineSeriesItem(_chartItem).yValue.toString();
            }

        }

        override protected function updateDisplayList(unscaledWidth:Number,unscaledHeight:Number):void

        {

            super.updateDisplayList(unscaledWidth, unscaledHeight);
            var ls:LineSeries = _chartItem.element as LineSeries;
            solidColor = new SolidColor(ls.getStyle("fill"));
            _label.setActualSize(_label.getExplicitOrMeasuredWidth(),20);
            _label.move(unscaledWidth - _label.getExplicitOrMeasuredWidth() / 2 , this.unscaledHeight - _label.getExplicitOrMeasuredHeight() - 5);

        }
    }

}

它运作良好。但是,由于 LineSeries 可能已经使用其他 ItemRenderer 设置,例如CircleItemRendererBoxItemRenderer。我找不到让我用一个 LineSeries 设置多个 ItemRender 的地方。我想知道最好的方法是什么。

4

1 回答 1

0

感谢 Sunil D.

ItemRenderer最后我创建如下扩展

public class LSLabelCircleItemRenderer extends CircleItemRenderer
    {
        private var _label:Label;
        public function LSLabelCircleItemRenderer():void
        {
            super();
            _label = new Label();
        }
        override protected function updateDisplayList(unscaledWidth:Number,unscaledHeight:Number):void
        {
            super.updateDisplayList(unscaledWidth, unscaledHeight);
            if(data != null){
                var ls:LineSeries = ChartItem(data).element as LineSeries;
                label.text = LineSeriesItem(data).yValue.toString();
                skin.parent.addChild(label);
                label.setStyle("color",ls.getStyle("fill"));
                label.move(skin.x - label.getExplicitOrMeasuredWidth() / 5,skin.y - label.getExplicitOrMeasuredHeight());
            }
        }       
    }
于 2013-07-02T07:01:25.573 回答