UniqueCategoryAxis --> CategoryAxis with unique values

        import mx.charts.CategoryAxis;
        import mx.collections.ListCollectionView;
        import mx.collections.Sort;
        import mx.collections.SortField;

        public class UniqueCategoryAxis extends CategoryAxis {
                
                private var theDataSort:Sort = new Sort();      
        
                private var tmp:Object = {}; // used to 
removeDuplicates
                                
                override public function set dataProvider
(value:Object):void{                     
//                      trace('!!!!!!!!!!!!UniqueCategoryAxis.set 
dataProvider');
                        tmp = {};
                        var label:Object = categoryField?
categoryField:dataFunction as Object;
                        super.dataProvider = (value && value.toArray
())?
                                                                
                                value.toArray().filter(         
                
                                function
(item:Object,idx:uint,arr:Array):Boolean {                      
                        var pk:String = item[label] as String;
                        if (tmp.hasOwnProperty(pk)){            
                        
                                return false;
                        } else {
                                tmp[pk] = item;                 
        
                                return true;
                        }
                        }):value;
                        
                        theDataSort.fields = [new SortField(label as 
String,false,true,false)];/** Sorting desc*/
                super.dataProvider.sort = theDataSort;
                        super.dataProvider.refresh();    
                }
        }               

--- In [email protected], "Tim Hoff" <[EMAIL PROTECTED]> wrote:
>
> 
> Hey Vijay,
> 
> For some reason, I don't have the com.adobe.utils.ArrayUtil class; 
so I
> can't compile your app.  But, instead of using an array for the
> CategoryAxis's dataProvider, you may want to switch to an
> ArrayCollection.  Binding doesn't play nice with arrays.  If that
> doesn't help, you could change the logic to find duplicates to use a
> Dictionary or just use a loop to see if the item already exists.  
You're
> definitely close, so I'm sure that you'll figure it out; if you 
haven't
> already.
> 
> Cheers,
> -TH
> 
> --- In [email protected], "Vijay Anand Mareddy" <vam2@>
> wrote:
> >
> >
> > Thanks Tim, the hardcoded uniqueArr as dataprovider works but it
> doesnt
> > work when i try to use it as a derived function as follows.
> >
> > <?xml version="1.0" encoding="utf-8"?>
> >
> > <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml";
> >
> > layout="absolute">
> >
> > <mx:Script>
> >
> > <![CDATA[
> >
> > import mx.controls.Alert;
> >
> > import mx.collections.ArrayCollection;
> >
> > import com.adobe.utils.ArrayUtil;
> >
> >
> >
> > [Bindable]
> >
> > public var someData:ArrayCollection = new ArrayCollection([
> >
> > {editedEndDate:"01/01/2006", mpid:"GRAPES"},
> >
> > {editedEndDate:"05/01/2007", mpid:"APPLE"},
> >
> > {editedEndDate:"11/01/2009", mpid:"APPLE"},
> >
> > {editedEndDate:"05/01/2008", mpid:"ORANGE"},
> >
> > {editedEndDate:"05/01/2009", mpid:"MANGO"}
> >
> > ]);
> >
> >
> >
> > //[Bindable]
> >
> > //public var uniqueArr:Array = 
["GRAPES","APPLE","ORANGE","MANGO"];
> >
> >
> >
> > [Bindable]
> >
> > private var _uniqueArr:Array = new Array();
> >
> > public function set uniqueArr(arry:Array):void{
> >
> > _uniqueArr = arry;
> >
> > }
> >
> > public function get uniqueArr():Array{
> >
> > _uniqueArr = new Array();
> >
> > for each( var o:Object in mychart.dataProvider){
> >
> > Alert.show(o.mpid.toString());
> >
> > if(!ArrayUtil.arrayContainsValue(_uniqueArr,o.mpid)){
> >
> > //Alert.show(o.mpid.toString());
> >
> > _uniqueArr.push(o.mpid);
> >
> > }
> >
> > }
> >
> > return _uniqueArr;
> >
> > }
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > ]]>
> >
> > </mx:Script>
> >
> >
> >
> > <mx:Panel title="DateTimeAxis" width="100%" height="100%">
> >
> > <mx:PlotChart id="mychart" dataProvider="{someData}">
> >
> > <mx:horizontalAxis><mx:DateTimeAxis dataUnits="days"
> > /></mx:horizontalAxis>
> >
> > <mx:verticalAxis><mx:CategoryAxis dataProvider="{uniqueArr}"
> > /></mx:verticalAxis>
> >
> > <mx:series><mx:PlotSeries yField="mpid" xField="editedEndDate"
> > displayName="myData"/></mx:series>
> >
> > </mx:PlotChart>
> >
> > </mx:Panel>
> >
> >
> >
> > </mx:Application>
> >
> > -VM
> >
> >
> > --- In [email protected], "Tim Hoff" TimHoff@ wrote:
> > >
> > >
> > > Hi Vijay,
> > >
> > > This will get rid of your duplicate Apple.
> > >
> > > <mx:CategoryAxis dataProvider="{uniqueArr}"/>
> > >
> > > Although you have the uniqueArr hardcoded, you can derive that 
from
> > the
> > > data.
> > >
> > > -TH
> > >
> > > --- In [email protected], "Vijay Anand Mareddy" vam2@
> > > wrote:
> > > >
> > > > How do i make the CategoryAxis show only unique values
> > > >
> > > > In my example, I dont want the Apple to apear twice on the
> vertical
> > > > axis.
> > > >
> > > > <?xml version="1.0" encoding="utf-8"?>
> > > > <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml";
> > > > layout="absolute">
> > > > <mx:Script>
> > > > <![CDATA[
> > > > import mx.controls.Alert;
> > > > import mx.collections.ArrayCollection;
> > > > import com.adobe.utils.ArrayUtil;
> > > >
> > > > [Bindable]
> > > > public var someData:ArrayCollection = new ArrayCollection([
> > > > {editedEndDate:"01/01/2006", mpid:"GRAPES", modelId:1},
> > > > {editedEndDate:"05/01/2007", mpid:"APPLE",
> > > > modelId:23},
> > > > {editedEndDate:"11/01/2009", mpid:"APPLE", modelId:160},
> > > > {editedEndDate:"05/01/2008", mpid:"ORANGE",
> > > > modelId:4},
> > > > {editedEndDate:"05/01/2009", mpid:"MANGO", modelId:5}
> > > > ]);
> > > >
> > > > [Bindable]
> > > > public var uniqueArr:Array = 
["GRAPES","APPLE","ORANGE","MANGO"];
> > > >
> > > > private function uniqueMPIDFunc(axis:CategoryAxis,
> > > > item:Object):Object {
> > > > if(ArrayUtil.arrayContainsValue(ArrayCollection
> > > > (axis.dataProvider).toArray(),item.mpid)){
> > > > Alert.show("exist:"+item.mpid+":");
> > > > return new Object();
> > > > } else {
> > > > Alert.show("new:"+item.mpid+":");
> > > > return item.mpid;
> > > > }
> > > >
> > > > }
> > > >
> > > >
> > > > ]]>
> > > > </mx:Script>
> > > >
> > > > <mx:Panel title="DateTimeAxis" width="100%" height="100%">
> > > > <mx:PlotChart id="mychart" dataProvider="{someData}"
> > > > showDataTips="true">
> > > > <mx:horizontalAxis>
> > > > <mx:DateTimeAxis dataUnits="days" />
> > > > </mx:horizontalAxis>
> > > > <mx:verticalAxis>
> > > > <mx:CategoryAxis
> > > > dataFunction="uniqueMPIDFunc"/>
> > > > </mx:verticalAxis>
> > > > <mx:series>
> > > > <mx:PlotSeries yField="mpid"
> > > > xField="editedEndDate" displayName="myData"/>
> > > > </mx:series>
> > > > </mx:PlotChart>
> > > > </mx:Panel>
> > > >
> > > > </mx:Application>
> > > >
> > >
> >
>


Reply via email to