<?xml version="1.0"?>
<!-- charts/AddDataItem.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns="*" xmlns:ns1="com.anychart.*" layout="absolute" creationComplete="initChart();" viewSourceURL="srcview/index.html">
    <mx:TabNavigator width="559" height="422" id="tabCtrl" creationPolicy="all" horizontalCenter="0" verticalCenter="2">
        <mx:Canvas label="Chart Preview" width="100%" height="100%" id="chartPage">
            <ns1:AnyChartFlex x="0" y="0" width="100%" height="100%" id="chart"/>
        </mx:Canvas>
        <mx:Canvas label="Output XML" width="100%" height="100%">
            <mx:TextArea x="10" y="10" width="537" height="369" id="editOutputXML"/>
        </mx:Canvas>
    </mx:TabNavigator>
    
    <mx:Script>
        <![CDATA[
            import mx.collections.XMLListCollection;
            import mx.collections.ICollectionView;
            import mx.collections.ArrayCollection;
            
            public var expenses:ArrayCollection = new ArrayCollection([
                {Month:"January", Profit:2000000, Expenses:1500000,ENo:100},
                {Month:"February", Profit:1000000, Expenses:200000,ENo:80},
                {Month:"March", Profit:1500000, Expenses:500000,ENo:110},
                {Month:"April", Profit:1500000, Expenses:500000,ENo:130}
             ]);
             
             
             private function createSeriesFromAC(collection:ArrayCollection,nameField:String,yField:String,type:String=null,seriesName:String=null):XML
             {
                 var seriesXML:XML=<series/>;
                 if(seriesName!=null) seriesXML.@name=seriesName;
                 if(type!=null) seriesXML.@type=type;
                 
                 for(var i:int=0;i<collection.length;i++) {
                     seriesXML.appendChild(<point name={collection[i][nameField]} y={collection[i][yField]}/>);
                 }
                 return seriesXML;
             }
             
             private function initChart():void
             {
                 var xmlData:XML=
                     <anychart>
                         <charts>
                             <chart plot_type="CategorizedVertical">
                                 <data>
                                     {createSeriesFromAC(expenses,"Month","Profit","Bar","Profit")}
                                     {createSeriesFromAC(expenses,"Month","Expenses","Bar","Expenses")}
                                     {createSeriesFromAC(expenses,"Month","ENo","Bar","ENo")}
                                 </data>
                                 <chart_settings>
                                     <title><text>Company Status</text></title>
                                     <legend enabled="true">
                                         <title enabled="false"/>
                                     </legend>         
                                     <axes>
                                         <y_axis><title enabled="false"/></y_axis>
                                         <x_axis><title enabled="false"/></x_axis>
                                     </axes>                            
                                 </chart_settings>
                             </chart>
                         </charts>
                     </anychart>;
                 
                 chart.anychartXML=xmlData;
                 editOutputXML.text=xmlData.toXMLString();                 
             }
        ]]>
    </mx:Script>
</mx:Application>