3 Replies Latest reply on Sep 3, 2008 11:45 AM by Newsgroup_User

    Need to chart attribute value of just one child node of XML document

    whertzing
      I have a XML document with (for example) 7 parent nodes, each parent node has 5 child nodes. The parent nodes have an attribute @EarlierDTS (DateTime type) that is the x-axis category of a chart. Each child node has an attribute @eventid which specifies the id of the event, and another atttribute @NumOccurs which specifies how many times that event occured in that period.

      How do I tell Flex I want a simple line chart of the eventID = 215? What if I want two lines, for both eventID=215 and eventid=307?

      I have studied the posts and blogs for over a week now, and have seen this question or similar come up quite a few places, with no answer.

      1) Should I focus on learning how to create a filterfunction for the XMLList that underlies my XMLListCollection so that the filtered data view is just one child node per parent node ( or two child nodes for the second case)? And set the filtered data view as the dataprovider of my chart's vertical series?

      2) Should I focus on learning how to create a XML Filter query that selects just one or two child nodes for each parent node, and set the charts' series' dataprovider to this filter expression? (I don't think this is allowed - but I'm checking with the forum members...)

      3) Should I focus on learning how to convert the XMLListCollection into a HierarchicalData object, and then learning how to filter this object so there is only one (or two) childs per parent? This seems like a lot of coding - I almost have to create a pair of classes - one for the parent and one for the child - so I can create nested ArrayObjects.

      4) Should I create a brand new XMLList by walking the original XML list, and inserting Parent nodes and just the child nodes that match the eventID(s) I want to chart, into the new XMLList?

      I believe that the easiest way would be to create a Filterfunction for the XMLList, and bind the chart series to the (filtered) XML List. But the problem with this approach is that I have seen more than 2 posts asking how to accomplish filtering that removes specific children from the view, with no solutions posted.

      Help! What is the best way to get just one child for each parent, from an XMLList?
        • 1. Re: Need to chart attribute value of just one child node of XML document
          Level 7

          "whertzing" <webforumsuser@macromedia.com> wrote in message
          news:g995si$2l3$1@forums.macromedia.com...
          >I have a XML document with (for example) 7 parent nodes, each parent node
          >has 5
          > child nodes. The parent nodes have an attribute @EarlierDTS (DateTime
          > type)
          > that is the x-axis category of a chart. Each child node has an attribute
          > @eventid which specifies the id of the event, and another atttribute
          > @NumOccurs
          > which specifies how many times that event occured in that period.
          >
          > How do I tell Flex I want a simple line chart of the eventID = 215? What
          > if I
          > want two lines, for both eventID=215 and eventid=307?
          >
          > I have studied the posts and blogs for over a week now, and have seen this
          > question or similar come up quite a few places, with no answer.
          >
          > 1) Should I focus on learning how to create a filterfunction for the
          > XMLList
          > that underlies my XMLListCollection so that the filtered data view is just
          > one
          > child node per parent node ( or two child nodes for the second case)? And
          > set
          > the filtered data view as the dataprovider of my chart's vertical series?
          >
          > 2) Should I focus on learning how to create a XML Filter query that
          > selects
          > just one or two child nodes for each parent node, and set the charts'
          > series'
          > dataprovider to this filter expression? (I don't think this is allowed -
          > but
          > I'm checking with the forum members...)
          >
          > 3) Should I focus on learning how to convert the XMLListCollection into a
          > HierarchicalData object, and then learning how to filter this object so
          > there
          > is only one (or two) childs per parent? This seems like a lot of coding -
          > I
          > almost have to create a pair of classes - one for the parent and one for
          > the
          > child - so I can create nested ArrayObjects.
          >
          > 4) Should I create a brand new XMLList by walking the original XML list,
          > and
          > inserting Parent nodes and just the child nodes that match the eventID(s)
          > I
          > want to chart, into the new XMLList?
          >
          > I believe that the easiest way would be to create a Filterfunction for the
          > XMLList, and bind the chart series to the (filtered) XML List. But the
          > problem
          > with this approach is that I have seen more than 2 posts asking how to
          > accomplish filtering that removes specific children from the view, with no
          > solutions posted.
          >
          > Help! What is the best way to get just one child for each parent, from an
          > XMLList?

          I'd just look at a dataFunction. There's an example here that may point you
          in the right direction:
          http://flexdiary.blogspot.com/2008/08/charting-example.html

          HTH;

          Amy


          • 2. Re: Need to chart attribute value of just one child node of XML document
            whertzing Level 1
            Thanks Amy. Your example was very helpful, as were your many other FLEX blog entries. Very much appreciated as I learn the intricacies of the FLEX API.

            For those looking for the solution to the problem as stated, the following is taken from Amy's example with some slight modifications. Any errors here are all mine...

            1) Create a dataFunction in ActionScript as follows:

            private function eventCountDataFunction(series:Series, item:XML, fieldName:String):Object{
            switch(fieldName){
            case ('yValue'):
            return item.child('EE').(attribute('EventID')==417).attribute('NumOccurs');
            case ('xValue'):
            return item.attribute('EarlierDTS');
            default:
            //lineseries shouldn't ever do this, but better safe than sorry
            return null;
            }

            2) Add the dataFunction to your series. Amy does this in ActionScript, here's how I do it in mxml:

            <mx:series>
            <mx:ColumnSeries dataFunction="eventCountDataFunction" showDataEffect="{interpolate}">
            </mx:ColumnSeries>
            </mx:series>


            • 3. Re: Need to chart attribute value of just one child node of XML document
              Level 7

              "whertzing" <webforumsuser@macromedia.com> wrote in message
              news:g9mk1d$nu3$1@forums.macromedia.com...
              > Thanks Amy. Your example was very helpful, as were your many other FLEX
              > blog
              > entries. Very much appreciated as I learn the intricacies of the FLEX API.

              You're welcome :-)