3 Replies Latest reply on May 7, 2008 12:17 PM by ntsiii

    Changing dataprovider


      I have an httpservice:
      url=" http://localhost:8180/Main"

      and a ColumnChart:
      width="100%" height="100%">

      and the XML returned is as follows:

      and this works fine ..

      I change the params to the httpservice based on some other user interaction and resend the request on the service "srv" and get back a different XML

      My question is how do I dynamically change the dataprovider to parse this new XML? Is handling the result in the result event handler the only way?

      I am trying the following:
      public function srvResult(event:ResultEvent):void
      var result:Object = event.result;
      var myXML:XML = new XML(result);

      chart.dataProvider = myXML.A.B;

      this does not work even when I change the formattype to e4x in the service - so does not work either ways. (The XML does show up in the result handler - the assignment to the dataprovider does not seem to be updating the chart).

      Now, I can always parse the XML in the result handler and then update an array and bind the chart to the array etc. However, isnt there a way to dynamically tell the dataprovider to expect a different XML format?

      Thanks in advance.

        • 1. Changing dataprovider
          Brent Lamborn Level 2
          Have you tried just removing dataProvider="{srv.lastResult.X.Y}" from your ColumnChart and just always use the srvResult handler to assign the dataProvider?

          I think that might be the problem.Try not explicitly setting the dataProvider in the ColumnChart tag, alway do it from the result event handler. You'll have to add some logic to decide what the dataProvider is (ie. myXML.A.B or myXML.X.Y ).
          • 2. Re: Changing dataprovider

            Yes, I did try that. It didnt work (data did not get updated).
            Now, I am trying to assign the the XML subnodes into an ArrayCollection or XMLListCollection but am getting Type coercion error. First, I'll try to solve this problem now.
            • 3. Re: Changing dataprovider
              ntsiii Level 3
              Never bind directly to lastResult in a real-world app. It is too inflexible.

              Brent suggestion assigning the dataProvider directly. but do not use "new" with XML(). XML() is really a top-level function not a class. And skip the Object var:

              public function srvResult(event:ResultEvent):void
              var myXML:XML = XML(event.result);
              trace(myXML.A.B.toXMLString()); //to verify your expression
              chart.dataProvider = myXML.A.B;

              Alternatively, declare a [Bindable] instance variable, set that in the handler, and bind to it:
              private var _xlcResults:XMLListCollection;
              public function srvResult(event:ResultEvent):void
              var myXML:XML = XML(event.result);
              _xlcResults = new XMLListCollection(myXML.A.B);
              trace(_xlcResults.toXMLString()); //to verify your expression
              <mx:ColumnChart ... dataProvider="{_xlcResults}"