<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" 
    xmlns:charts="com.iwobanas.charts.*" viewSourceURL="srcview/index.html">
    <mx:Script>
        <![CDATA[
            import mx.collections.ArrayCollection;
            import mx.charts.chartClasses.IAxis;
            
            /**
            * Axis label function converting category index to category name.
            */
            public function categoryLabelFunction(labelValue:Object, previousValue:Object, axis:IAxis):String
            {
                var index:int = int(labelValue);
                
                if (index >= 0 && index < categories.length)
                    return categories[index];
                return "";
            }
            
            /**
             * Convert category name to category index - the numeric value which then can be placed on LinearAxis.
             */
            public function categoryParseFunction(category:Object):Number
            {
                if (!categories.contains(category))
                {
                    categories.addItem(category);
                }
                return categories.getItemIndex(category);
            }
            
            public var categories:ArrayCollection = new ArrayCollection();
            
            [Bindable]
            public var profitDP:ArrayCollection = new ArrayCollection( [
                { Month: "Jan", Profit: 2000 }, { Month: "Feb", Profit: 1000 },
                { Month: "Mar", Profit: 1500 }, { Month: "Apr", Profit: 1800 },
                { Month: "May", Profit: 2400 } ]);
                
            [Bindable]
            public var expensesDP:ArrayCollection = new ArrayCollection( [
                { Month: "Jan", Expenses: 1500 }, /* { Month: "Feb", Expenses: 200 }, */
                { Month: "Mar", Expenses: 500 }, { Month: "Apr", Expenses: 1200 },
                { Month: "May", Expenses: 575 } ]);
                
               [Bindable]
            public var amountDP:ArrayCollection = new ArrayCollection( [
                { Month: "Jan", Amount: 450 }, { Month: "Feb", Amount: 600 },
                /* { Month: "Mar", Amount: 300 }, */ { Month: "Apr", Amount: 900 },
                { Month: "May", Amount: 500 } ]);

        ]]>
    </mx:Script>
    
    <charts:ChartScroller chart="{columnChart}" />
    
    <mx:Panel title="ChartScroller - CategoryAxis simulation 2" width="100%" height="100%">
        
        <mx:ColumnChart id="columnChart" width="100%" height="100%" 
            gutterLeft="50" gutterRight="40">
            <mx:series>
                <!-- This time xField and dataProviders are specified -->
                <mx:ColumnSeries yField="Profit" xField="Month" dataProvider="{profitDP}" />
                <mx:ColumnSeries yField="Expenses" xField="Month" dataProvider="{expensesDP}" />
                <mx:ColumnSeries yField="Amount" xField="Month" dataProvider="{amountDP}" />
            </mx:series>
            <mx:horizontalAxis>
                <!-- LinearAxis simulating CategoryAxis -->
                <mx:LinearAxis interval="1" 
                    labelFunction="categoryLabelFunction" 
                    parseFunction="categoryParseFunction" />
            </mx:horizontalAxis>
        </mx:ColumnChart>
        
    </mx:Panel>

</mx:Application>