2 Replies Latest reply on Mar 16, 2010 8:16 AM by SunilAdobe

    building charts from xml

    new2oop Level 1

      I'm trying to build a series of charts from xml (sample below). Examples might be a column chart of all scores, or a column chart of all 'fred' values. All the examples I've seen are ArrayCollections, or if they are XML, they are very simple xml. I've tried converting the xml to an ArrayCollection (didn't work) and I've tried using the xml as the datasource. I could loop through and build a simple xml for each chart but there must be an easier way. Any suggestions.

       

      <results>
                      <item name="group1" speed="100" score="23" time="123">
                          <detail>
                              <element name='fred'>2</element>
                              <element name='john'>3</element>
                          </detail>
                      </item>

                      <item name="group2" speed="10" score="3" time="1">
                           <detail>
                               <element name='fred'>12</element>
                               <element name='john'>31</element>
                           </detail>
                       </item>

                      <item name="group3" speed="230" score="53" time="78">
                           <detail>
                               <element name='fred'>42</element>
                               <element name='john'>81</element>
                           </detail>
                       </item>

      </results> 

        • 1. Re: building charts from xml
          new2oop Level 1

          Charting most of the values is ok but I can't chart the values of the 'element' array. I've tried a number of values for the yField:

           

          yField="item.@name ==fred"

          yField="item.detail.@name ==fred"

          yField="item.detail[0]"

           

          and none of them work. Here's the chart:

           

           

           

                  <mx:ColumnChart id="column0" height="100%" color="0x323232"
                               showDataTips="true" dataProvider="{medalsAC}">

                      <mx:series>
                          <mx:ColumnSeries yField="item.@name ==fred" displayName="Players"/>
                      </mx:series>
                  </mx:ColumnChart>

          • 2. Re: building charts from xml
            SunilAdobe Adobe Employee

            Charting framework access the fields like this item[yField] so any of the y field values that you have given does not work i.e. item["item.detail[0]"] etc. do not work.

            For this purpose we created a property called dataFunction on Series, CategoryAxis classes through which you can provide appropriate value for your fields.

             

            From the livedocs - http://livedocs.adobe.com/flex/3/langref/mx/charts/chartClasses/Series.html#dataFunction

             

            You typically use the dataFunction property to access fields in a data provider that are not scalar values, but are instead nested in the data provider. For example, the following data requires a data function to access the fields for a chart's data provider:

             

                  , open:25.19}

                   

            The following example returns a value from this data provider:

             

                 public function myDataFunction(series:Series, item:Object, fieldName:String):Object {

                      if(fieldName == 'yValue')

                          return(item.close.High);

                      else if(fieldName == "xValue")

                          return(item.month);

                      else

                          return null;

                 }    

             

            Thanks

            -Sunil