1 Reply Latest reply on Sep 7, 2010 6:21 AM by Adel_M

    CategoryAxis in BarChart

    Adel_M

      Hello,

       

      I have a barchart, that I am transforming to a gantt chart since Flex Base Charts don't have a gantt chart,

       

      Anyhow, the issue that I am facing, is tha the vertical axis (which is category type now) does not sort and combine same datapoints...

       

      Anyone can help...code is below

       

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"  layout="absolute" minWidth="955" minHeight="600" initialize="test()">
          
           <mx:Script>
               <![CDATA[
                   import mx.charts.series.BarSet;
                   import mx.collections.ArrayCollection;
                   import mx.formatters.*;
                   [Bindable]
                   public var datarows:ArrayCollection;
                   public var dem:ArrayCollection = new ArrayCollection();

       

                  public function myParseFunction(s:Number):Date {
                       var gmtDate:Date = new Date();
                       //s = s / 1000;
                       gmtDate.setTime(Math.round((s/1000)*(1000))+(gmtDate.timezoneOffset*60*1000));
                       return gmtDate;
                      
                       // Get an array of Strings from the comma-separated String passed in.
                       //var a:Array = s.split(",");
                       // Create the new Date object. Subtract one from
                   }
              
                   private function removedDuplicates(item:Object):Boolean
                   {
                      
                       if (myCombinedArray.contains(item)) {
                           /* If the keys Object already has this property,
                           return false and discard this item. */
                           return false;
                       } else {
                           /* Else the keys Object does *NOT* already have
                           this key, so add this item to the new data
                           provider. */
                           myCombinedArray.addItem(item);
                           var objx:Object = new Object();
                           objx.combinedArray = item;
                           return true;
                       }

       

                  }

       

                  public function test():void
                   {
                       var collection:ArrayCollection = new ArrayCollection();
                       collection.addItem(new ArrayCollection(["1282927901000", "mi", "100.0", "130", "6", "9"]));
                       collection.addItem(new ArrayCollection (["1282927905000", "mi", "50.0", "130", "5", "7"]));
                       collection.addItem(new ArrayCollection (["1282927910000", "mi", "300.0", "340", "4", "8"]));
                       collection.addItem(new ArrayCollection(["1282927930000", "mi", "400.0", "540", "3", "10"]));
                       collection.addItem(new ArrayCollection (["1282927940000", "mi", "500.0", "820", "2", "12"]));
                       collection.addItem(new ArrayCollection (["1282927950000", "mi2", "600.0", "930", "8", "15"]));
                       collection.addItem(new ArrayCollection(["1282927960000", "mi2", "700.0", "620", "1", "6"]));
                       collection.addItem(new ArrayCollection (["1282927970000", "mi2", "800.0", "420", "9", "17"]));
                       collection.addItem(new ArrayCollection (["1282927980000", "mi2", "900.0", "730", "14", "28"]));
                       collection.addItem(new ArrayCollection(["1282928040000", "mi12", "59000.0", "140", "13", "18"]));
          
                      
                       datarows = new ArrayCollection();
                       var myCombinedArray:ArrayCollection = new ArrayCollection();
                  
                       for each(var ac:ArrayCollection in collection){
                           var obj:Object = new Object();
                           obj.time = ac[0];
                           obj.url = ac[1];
                           obj.endDT = ac[2];
                           obj.sumEndDT = ac[3];
                           //obj.hits = ac[4];
                           datarows.addItem(obj);
                          
                          
                           dem.addItem(ac[1]);
                          
                           //obj.combinedArr = dem[1];
                       //    obj.combinedArr = dem[2];
                       }
                       dem.filterFunction = removedDuplicates;
                       dem.refresh();
                       obj.combinedArr = dem;
                      
                      
                      
                      
                   }

       

              ]]>
           </mx:Script>
           <mx:BarChart type="stacked" width="100%" >
              
               <mx:verticalAxis>
                   <mx:CategoryAxis categoryField="combinedArr" dataProvider="{datarows}"/>
               </mx:verticalAxis>
              
              
               <mx:series>
                   <mx:BarSeries xField="time" visible="false" dataProvider="{datarows}" />
                   <mx:BarSeries xField="endDT" visible="true" dataProvider="{datarows}"/>
                   <mx:BarSeries xField="sumEndDT" visible="true" dataProvider="{datarows}"/>
               </mx:series>
               <mx:horizontalAxis>
               <mx:DateTimeAxis  parseFunction="myParseFunction" autoAdjust="true" dataUnits="seconds" displayLocalTime="true"/>
               </mx:horizontalAxis>
              
          
           </mx:BarChart>
           <mx:ArrayCollection id="myCombinedArray">
              
           </mx:ArrayCollection>
      </mx:Application>