1 Reply Latest reply on Nov 28, 2007 1:55 PM by ntsiii

    Chart HTTPservice & for loop

      I am using a togglebuttonbar to navigate between 3 seperate linecharts, each displaying unique data. My problem is that with my current code only the last chart is displaying any data. Everytime I change which chart is displayed last it is always the last chart that displays properly.

      So my code lloks like this:



      For Loop(example: loops 3 times){

      new Canvas(added as child to viewstack)

      new Panel(addd as child to canvas)

      new Chart

      new Array (for line series)

      FOR LOOP(example: 2 times){
      new Line
      line.yfeild = NAME
      push line into line series array

      HTTPservice to get the data, calls dataReceived function, which is within this for loop

      dataReceived{ Chart.dataProvider = event;} // te httpservice works, Ive checked it in debugging, and because the last chart displays properly



      So that should display 3 charts, each with two lines. Note that the httpservice is calling the same chunk of XML for every chart, but Im only displaying a couple portions in the each individual chart. (for example, the xml file has: APPLES, ORANGES, BANANAS. one cahrt would display apples, the next bananas, etc)

      A useful chunk of code is beow... once again, only the last chart's data is being displayed.

      var DB_Connect:Object = new Object;
      var URL:String = new String;
      URL = ""


      _newChart.series = _newSeries;

      function dataReceived(evt:ResultEvent):void
      _newChart.dataProvider = evt.result.point;

      thats from inside the first for loop. I'm certain Im making some noob mistake!

        • 1. Re: Chart HTTPservice & for loop
          ntsiii Level 3
          the newChart object is getting created synchronously, but the data is comming asynchronously.

          You need to store a reference to each new child instance, perhaps in an associative array(object) as it is created. Then in the result handler, assign the current result to the appropriate chart.

          Probably need AsyncToken to match call to result.