2 Replies Latest reply on Sep 29, 2008 6:04 AM by Newsgroup_User

    Could someone help me with a function that would go into an arraycollection

    nikos101 Level 2
      I have a chart that plots the amounts of comments per day. However it does not plot values where there were no comments in the day because in the original data when they are no comments for that day, this data is not recorded. Could someone help me with a function that would go into an arraycollection which has a date(for the datetime axis) and amount which is a uint properties, then in the function it would insert a value of 0 where there is no data for a day. Eg

      if my array collection is

      {
      [07/23/05,2],
      [07/25/05,3],
      [07/27/05,4],

      }


      then the function would return

      {
      [07/23/05,2],
      [07/24/05,0],
      [07/25/05,3],
      [07/26/05,0],
      [07/27/05,4],

      }

      Thanks for any help on this :)
        • 1. Re: Could someone help me with a function that would go into an arraycollection
          dietmar.paulus Level 1
          Hey maybe this will help you



          <?xml version="1.0" encoding="utf-8"?>
          <mx:Application
          xmlns:mx=" http://www.adobe.com/2006/mxml" creationComplete="onCC()"
          layout="absolute" backgroundAlpha="0" xmlns:local="*">

          <mx:Script>
          <![CDATA[
          import mx.collections.ArrayCollection;

          private var arcData:ArrayCollection = new ArrayCollection([["07/23/05",2],
          ["07/25/05",3],
          ["07/27/05",4]]);


          private function onCC():void
          {
          var i:int = 0;
          var data:Array;
          var strDate:String;
          var tmp1:String;
          var tmp2:String;


          var tmpDateArc:ArrayCollection = new ArrayCollection();

          //Modify to correct date-form
          for(i = 0; i < arcData.length; i++)
          {
          data = arcData as Array;
          strDate = data[0];
          tmp1 = strDate.substring(0,6);
          tmp2 = strDate.substring(6);
          strDate = tmp1 + "20" + tmp2;
          data[0] = strDate;
          tmpDateArc.addItem(strDate);
          }

          var firstDate:Date = new Date(Date.parse(arcData[0][0]));
          var lastDate:Date = new Date(Date.parse(arcData[arcData.length - 1][0]));

          var oneDayInMilli:Number = 1000 * 60 * 60 * 24;

          for(var j:Number = firstDate.time + oneDayInMilli; j < lastDate.time; j = j + oneDayInMilli)
          {
          var tmpDate:Date = new Date(j);
          var strDateFormat:String = getTwoDigitDate(tmpDate.month + 1) + "/" +
          getTwoDigitDate(tmpDate.date) + "/" +
          tmpDate.fullYear;
          if(!tmpDateArc.contains(strDateFormat))
          arcData.addItem([strDateFormat,0]);
          }

          //Re-Modify to correct date-form
          for(i = 0; i < arcData.length; i++)
          {
          data = arcData
          as Array;
          strDate = data[0];
          tmp1 = strDate.substring(0,6);
          tmp2 = strDate.substring(8);
          strDate = tmp1 + tmp2;
          data[0] = strDate;
          }

          arcData.source = arcData.source.sort(sortFunc);
          arcData.refresh();

          for(i = 0; i < arcData.length; i++)
          {
          trace(arcData [0] + " --- " + arcData[1]);
          }
          }

          private function sortFunc(a:Object, b:Object):int
          {
          var yearA:int = int(String(a[0]).substring(6));
          var yearB:int = int(String(b[0]).substring(6));
          var monthA:int = int(String(a[0]).substring(0,2));
          var monthB:int = int(String(b[0]).substring(0,2));
          var dayA:int = int(String(a[0]).substring(3,5));
          var dayB:int = int(String(b[0]).substring(3,5));

          if(yearA < yearB)
          return -1;
          else if(yearA > yearB)
          return 1;
          else if(monthA < monthB)
          return -1;
          else if(monthA > monthB)
          return 1;
          else if(dayA < dayB)
          return -1;
          else if(dayA > dayB)
          return 1;
          else
          return 0;


          }

          private function getTwoDigitDate(date:int):String
          {
          if(date < 10)
          return "0" + date;
          else
          return "" + date;
          }
          ]]>
          </mx:Script>
          </mx:Application>


          cheers

          dietmar
          • 2. Re: Could someone help me with a function that would go into an arraycollection
            Level 7

            "nikos101" <webforumsuser@macromedia.com> wrote in message
            news:gbq2dm$fi9$1@forums.macromedia.com...
            >I have a chart that plots the amounts of comments per day. However it does
            >not
            > plot values where there were no comments in the day because in the
            > origianl
            > data when they are no comments for that day, this data is not recorded.
            > Could
            > someone help me with a function that would go into an arraycollection
            > which has
            > a date(for the datetime axis) and amount which is a uint properties, then
            > in
            > the function it would insert a value of 0 where there is no data for a
            > day. Eg
            >
            > if my array collection is
            >
            > {
            > [07/23/05,2],
            > [07/25/05,3],
            > [07/27/05,4],
            >
            > }
            >
            >
            > then the function would return
            >
            > {
            > [07/23/05,2],
            > [07/24/05,0],
            > [07/25/05,3],
            > [07/26/05,0],
            > [07/27/05,4],
            >
            > }
            >
            > Thanks for any help on this :)

            Line serieses have a property that will automatically interpolate missing
            data. Check the docs.