y-axis on area chart

9 views
Skip to first unread message

rohit

unread,
Sep 4, 2008, 5:30:25 AM9/4/08
to Flex India Community
I have one problem in area chart i.e.

I am passing the dataprovider to area chart and y-axis of area chart
is ----------from top to bottom

600
400
200
100
0(orizon)which automatically generated according to the data

but i want it in reverce order i.e.

0
100
200
400
600 i can't change in my arraycollection also data of x-axis can't be
change

Venkat Viswanathan

unread,
Sep 4, 2008, 3:00:08 PM9/4/08
to flex_...@googlegroups.com
Hi,

There is no direct way to do this, but there is a crooked way. In the dataFunction of the series, negate all the values of the field that is projected on the y-axis. And then in the labelFunction of the verticalAxis, negate it again.

Here is an example:

<?xml version="1.0"?>
<!-- charts/BasicLine.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
  <mx:Script><![CDATA[
   import mx.charts.chartClasses.Series;
   import mx.charts.chartClasses.IAxis;
     import mx.collections.ArrayCollection;
     [Bindable]
     public var expenses:ArrayCollection = new ArrayCollection([
        {Month:"Jan", Profit:2000, Expenses:1500, Amount:450},
        {Month:"Feb", Profit:1000, Expenses:200, Amount:600},
        {Month:"Mar", Profit:1500, Expenses:500, Amount:300}
     ]);
     
     private function diffLabel(item:Object, prevValue:Object, axis:IAxis):String{
     var str:String = String(Number(item)*-1);
    
     return str;
     }
     
     private function dataFunc(series:Series, item:Object, fieldName:String):Object {
     if (item.Expenses>0)
     item.Expenses = item.Expenses*-1; 
     return item;
     }
  ]]></mx:Script>
  <mx:Panel title="Line Chart">
     <mx:LineChart id="myChart" 
        dataProvider="{expenses}" 
        showDataTips="true"
     >
        <mx:horizontalAxis>
           <mx:CategoryAxis 
                dataProvider="{expenses}" 
                categoryField="Month"
            />
        </mx:horizontalAxis>
        <mx:verticalAxis>
         <mx:LinearAxis labelFunction="diffLabel"/>
        </mx:verticalAxis>
        <mx:series>
           <mx:LineSeries dataFunction="dataFunc" 
                yField="Profit" 
                displayName="Profit"
           />
           <mx:LineSeries 
                yField="Expenses" 
                displayName="Expenses"
           />
        </mx:series>
     </mx:LineChart>
     <mx:Legend dataProvider="{myChart}"/>
  </mx:Panel>
</mx:Application>


Regards,
Venkat
Reply all
Reply to author
Forward
0 new messages