Created
October 26, 2011 15:42
-
-
Save bendalton/1316741 to your computer and use it in GitHub Desktop.
BREAK-EVEN AREA CHART WITH FLEX
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0"?> | |
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" creationComplete="generateChartData()"> | |
<mx:Script><![CDATA[ | |
import mx.collections.ArrayCollection; | |
[Bindable] | |
public var chartData:ArrayCollection; | |
public function generateChartData():void | |
{ | |
var units:uint = results.result.NumberOfUnits; | |
chartData = new ArrayCollection(); | |
for(var i:uint = units; i > 0; i--){ | |
var item:Object = {}; | |
item.unitSales = i; | |
item.cost = getUnitCost(i); | |
item.revenue = getUnitRevenue(i); | |
chartData.addItem(item); | |
} | |
} | |
public function getUnitCost(unit:uint):Number | |
{ | |
// calculate unit cost | |
return 0; // return the current cost for that unit; | |
} | |
public function getUnitRevenue(unit:uint):Number | |
{ | |
// calculate unit revenue | |
return 0; // return the current revenue for that unit; | |
} | |
]]></mx:Script> | |
<!-- Load XML file --> | |
<fx:Declarations> | |
<fx:Model id="results" source="assets/break_even.xml" /> | |
</fx:Declarations> | |
<s:Group> | |
<mx:AreaChart id="chart" dataProvider="{chartData}" showDataTips="true"> | |
<mx:horizontalAxis> | |
<mx:CategoryAxis categoryField="unitSales" /> | |
</mx:horizontalAxis> | |
<mx:series> | |
<mx:AreaSeries displayName="Total Cost" yField="cost" /> | |
<mx:AreaSeries displayName="Total Revenue" yField="revenue" /> | |
</mx:series> | |
</mx:AreaChart> | |
<mx:Legend dataProvider="{chart}" /> | |
</s:Group> | |
</s:Application> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<data> | |
<result> | |
<TotalCost>1125</TotalCost> | |
<TotalRevenue>1250</TotalRevenue> | |
</result> | |
</data> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment