Main.mxml
<?xml version=”1.0″ encoding=”utf-8″?>
<mx:Application xmlns:mx=”http://www.adobe.com/2006/mxml” >
<mx:Script>
import mx.collections.ArrayCollection;
[Bindable]
public var dataCollection:ArrayCollection = new ArrayCollection([
{Month: "Jan", planned: 2000, actual:1856, average:1790 },
{Month: "Feb", planned: 1590, actual:1624, average:1790},
{Month: "Mar", planned: 1820, actual:1832,average:1790},
{Month: "Apr", planned: 1450, actual:1524, average:1790},
{Month: "May", planned: 1775, actual:1695, average:1790}]);
</mx:Script>
<mx:Panel>
<mx:ColumnChart id=”myChart” dataProvider=”{dataCollection}”
showDataTips=”true”>
<mx:horizontalAxis>
<mx:CategoryAxis dataProvider=”{dataCollection}”
categoryField=”Month”/>
</mx:horizontalAxis>
<mx:series>
<mx:ColumnSeries xField=”Month” yField=”planned” displayName=”Planned”/>
<mx:ColumnSeries xField=”Month” yField=”actual” displayName=”Actual”/>
<mx:ColumnSeries xField=”Month” yField=”average” displayName=”Average”
itemRenderer=”AverageLineRenderer”/>
</mx:series>
</mx:ColumnChart>
</mx:Panel>
</mx:Application>
AverageLineRenderer.as
package
{
import flash.display.Graphics;
import mx.charts.ChartItem;
import mx.charts.series.items.ColumnSeriesItem;
import mx.charts.series.items.LineSeriesItem;
import mx.controls.Label;
import mx.core.IDataRenderer;
import mx.core.UIComponent;
public class AverageLineRenderer extends UIComponent implements IDataRenderer
{
private var _chartItem:ChartItem;
private var _label:Label; // A label to place on the top of the column.
public function AverageLineRenderer():void
{
super();
// Add the label
_label = new Label();
addChild(_label);
_label.setStyle(“color”,0×000000);
}
public function get data():Object
{
return _chartItem;
}
public function set data(value:Object):void
{
if(value is ColumnSeriesItem)
{
_chartItem = value as ColumnSeriesItem;
if(_chartItem != null)
{
// Assigns the yValue to the label
if (ColumnSeriesItem(_chartItem).yValue!=null)
_label.text = “Average: ” + ColumnSeriesItem(_chartItem).yValue.toString();
else
_label.text=”";
}
}
}
override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
{
if ( _chartItem.index == 0) // Do it only for the first chartItem
{
super.updateDisplayList(unscaledWidth, unscaledHeight);
var g:Graphics = graphics;
g.clear();
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(-20,0,this.parent.width+20, 1);
g.endFill();
//Place the label
_label.setActualSize(_label.getExplicitOrMeasuredWidth(),_label.getExplicitOrMeasuredHeight());
_label.move(unscaledWidth ,-15);
}
}
}
}
'플렉스·플래시·액션스크립트3' 카테고리의 다른 글
amf 통신 시 규약 (0) | 2012.10.29 |
---|---|
컬럼 시리즈 하나만 데이터팁 비활성화 (0) | 2012.09.18 |
Event Model의 이해 (0) | 2012.08.10 |
UIComponent Lifecycle (0) | 2012.08.08 |
엄진영의 Custom Component 제작 강의 (0) | 2012.08.08 |