目前我已经创建了下面的类,它扩展了 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 设置,例如CircleItemRenderer
或BoxItemRenderer
。我找不到让我用一个 LineSeries 设置多个 ItemRender 的地方。我想知道最好的方法是什么。