技术交流

package
{
import flash.display.Graphics;
import flash.geom.Rectangle;

import mx.charts.chartClasses.LegendData;
import mx.charts.series.LineSeries;
import mx.charts.series.items.LineSeriesItem;
import mx.controls.Label;
import mx.core.IDataRenderer;
import mx.core.UIComponent;
import mx.graphics.Stroke;

public class LineRenderer extends UIComponent implements IDataRenderer
{
private var _label:Label;
private var _yField:String;
private var _color:Number;

private var _chartItem:LineSeriesItem;

public function LineRenderer():void
{
super();
_label = new Label();
addChild(_label);
}

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

public function set data(value:Object):void
{
if (_chartItem == value)
return;
if(value is LineSeriesItem) {
_chartItem = LineSeriesItem(value);
_label.text = _chartItem.yValue.toString()+"%";
_color = Stroke(LineSeries(_chartItem.element).getStyle("lineStroke")).color;
_label.setStyle("color",_color);
} else if(value is LegendData) {
_color = Stroke(LineSeries(LegendData(value).element).getStyle("lineStroke")).color;
}
}

override protected function updateDisplayList(unscaledWidth:Number,
  unscaledHeight:Number):void
{
super.updateDisplayList(unscaledWidth, unscaledHeight);
var rc:Rectangle = new Rectangle(0, 0, width , height );

var g:Graphics = graphics;
g.clear();
g.moveTo(rc.left,rc.top);
g.beginFill(_color);
g.drawCircle(4,4,1);
g.endFill();

_label.setActualSize(_label.getExplicitOrMeasuredWidth(),_label.getExplicitOrMeasuredHeight());
_label.move(unscaledWidth ,
unscaledHeight);
}

}
}

你可能感兴趣的:(Flash)