6 Replies Latest reply on Jan 5, 2007 4:46 PM by ntsiii

    getting dataProvider information on creation or initialize

    sf_dougco
      I am creating a graphing application fashioned from the "dashboard" example from adobe, and I want to do some dynamic line creation which works fine if I hard wire it. But I want to base the generation on things from the dataProvider source. I have this code:

      public function initUnits():void {
      var tt:Object = unitlines.dataProvider;
      trace(tt.length);
      }

      and

      <mx:LineChart dataProvider="{dataPoints}" showDataTips="true" id="unitlines" width="100%" height="100%" dataTipFunction="formatDataTip" creationComplete="initUnits()">

      Here's the odd thing -- the init function returns zero length, but if I postpone that routine until, let's say, the tip function gets called, then the length is correct. So, it seems that the dataProvider object is not getting fully set before the lineChart component calls my init routine!

      How can I get this so my init routine is called after the dataProvider object has it's data ??

      I have tried "initialize" instead of creationComplete, and also have tried both in the top level <mx statement

      Thanks

        • 1. Re: getting dataProvider information on creation or initialize
          sf_dougco Level 1
          OK, so the creationComplete DOES NOT take into account loading up the dataprovider info -- too bad there isn't a "onDataLoad" function call or something.

          So, I had to implement a Timer object that just loops until it detects the dataprovider object is fully loaded before proceeding with the function.
          • 2. Re: getting dataProvider information on creation or initialize
            peterent Level 2
            From what I can tell from your code, you shouldn't need to do anything like Timers. By specifying the data binding of dataProvider="{dataPoints}" you've indicated that whenever dataPoints is changed, the chart will get updated automatically.

            Is there any special reason why data binding isn't satisfying the problem?
            • 3. Re: getting dataProvider information on creation or initialize
              sf_dougco Level 1
              Sure, I can bind to the data, but the problem is that the lines I actually want to show via the lineseries will vary based on other filters, plus I want to be able to show more info in the tipfunction.

              The data I have is like:

              {time:1165158000000, 1:13.5, 2:14, 3:16, 4:15},
              {time:1165762800000, 1:14.5, 2:11, 3:13, 4:14},
              {time:1166367600000, 1:12.5, 2:13, 3:14, 4:13},
              {time:1166972400000, 1:15.5, 2:12, 3:15, 4:12},
              etc...

              and I need to specify a lineseries for each line, so I generate that dynamically via AS based on the data. BUT since I have the chart stuff in a separate MXML file (just like the flex sample "dashboard" does) from the MXML file that creates the data source, it doesn't know about the array completely at point of generation. Hence the timer in order to let it catch up. I COULD do the whole thing in one big MXML file I suppose, and then I would not have to worry about passing variables back and forth (which, by the way, is a big hassle! No easy globals except Application.application and I can't get a click event in my one MXML file to run a function that sits in another MXML file).


              • 4. Re: getting dataProvider information on creation or initialize
                peterent Level 2
                You can do all this stuff without timers. You'll want to use some custom events and make public variables [Bindable] between source/class files.

                Dynamically generating data or filtering a Collection will get handled correctly using just data binding.
                • 5. Re: getting dataProvider information on creation or initialize
                  sf_dougco Level 1
                  Well, I know that binding will cause the graph to change when I alter the values of things... but I do see what I describe in my first post. I should mention that I use the HTTP service to get the XML that creates the dataProvider, and this can delay 3 seconds or so while it does that.

                  But if you create an init function on the new class and trace the length of the dataprovider, it will be zero! Only until the HTTP service finishes will it be valid length, but of course it is too late because the init ran before the http finished.
                  • 6. Re: getting dataProvider information on creation or initialize
                    ntsiii Level 3
                    Do the work in the result handler. If you are not using one, do.
                    Tracy