2 Replies Latest reply on Aug 13, 2008 12:34 PM by Developer504

    Sort order in Charts

    Developer504 Level 1
      I noticed an odd thing in Flex. When I import data into my charts from XML files, it seems to reverse the order of the records.

      So for example, if I have the records:

      <projects>
      <job prName="Project A" hours="6705.50"/>
      <job prName="Project B" hours="3370.00"/>
      <job prName="Project C" hours="1223.50"/>
      </projects>

      It displays these in my barChart in the order C,B,A.

      Is there a simple way to reverse that order or do I have to put the data into an xmlListCollection and make a function to do it?

      M.
        • 1. Re: Sort order in Charts
          Level 7

          "Developer504" <webforumsuser@macromedia.com> wrote in message
          news:g7v9nf$te$1@forums.macromedia.com...
          >I noticed an odd thing in Flex. When I import data into my charts from XML
          > files, it seems to reverse the order of the records.
          >
          > So for example, if I have the records:
          >
          > <projects>
          > <job prName="Project A" hours="6705.50"/>
          > <job prName="Project B" hours="3370.00"/>
          > <job prName="Project C" hours="1223.50"/>
          > </projects>
          >
          > It displays these in my barChart in the order C,B,A.
          >
          > Is there a simple way to reverse that order or do I have to put the data
          > into
          > an xmlListCollection and make a function to do it?


          This is what I use:

          private function reverseData():void{

          var reverseSort:Sort= new Sort();

          reverseSort.compareFunction=reverseSortCompare;

          _data.sort=reverseSort;

          _data.refresh();

          }

          private function reverseSortCompare(a:XML, b:XML, fields:Array=null):int{

          if (a==null && b==null) return 0;

          var aIndex:int = a.childIndex();

          var bIndex:int = b.childIndex();

          if (aIndex==bIndex) return 0;

          if (bIndex>aIndex) return 1;

          if (aIndex>bIndex) return -1;

          //default

          return 0;

          }

          Where _data is the XMLListCollection that is being used as a dataProvider.



          HTH;


          • 2. Re: Sort order in Charts
            Developer504 Level 1
            Thanks Amy. I have a similar function using an XMLListCollection on another Chart already in my code, it seemed like a lot of code to do such a simple thing but I guess I'll do this. Any idea why Flex reverses the order?