3 Replies Latest reply on Jun 23, 2009 6:55 AM by rtalton

    Need help to get value from xmllist.

    xandesign

      Hi all,

       

      I have a little app which parses an external xml file using AS3 and displays the data in a line chart, see the xml sample below.

       

      The problem is I don't know how to dynamically get the @label attribute value, which I use as the series displayName, from the xml in my AS3 loop which builds the line chart series. I can't hardcode the value as I don't know how many 'series' tags will be within each 'items' tag in the xml as that number can change during run-time. See my displayChart() function code included below.

       

       

      Any help would be much appreciated, thanks in advance,

       

      Xander

       

       

      XML Sample

      <?xml version="1.0" encoding="UTF-8"?>
      <dataset>
      <items axis="L100">
      <series1 label="22-06-2009">0.00</series1>
      <series2 label="08-06-2009">0.00</series2>
      <series3 label="Average">6.06</series3>
      </items>
      <items axis="L200">
      <series1 label="22-06-2009">21.79</series1>
      <series2 label="08-06-2009">29.00</series2>
      <series3 label="Average">23.37</series3>
      </items>
      <items axis="L300">
      <series1 label="22-06-2009">8.96</series1>
      <series2 label="08-06-2009">12.21</series2>
      <series3 label="Average">10.22</series3>
      </items>

      </dataset>

       

       

      Snippet from my AS3 File

       

      private function displayChart(result:XML):void {
          var items:XMLList = result.elements('items') as XMLList;
          var itemsCount:int = items.length();
         
          var legend:Legend = new Legend();
         
          if (selectedChartQuery == 'chartquery1') {
              var chart:LineChart = new LineChart();
             
              chart.id = "chart1";
              chart.percentWidth = 94;
              chart.percentHeight = 90;
              chart.showDataTips = true;
              chart.styleName = "chart";
              chart.dataProvider = items;
             
              var axis:CategoryAxis = new CategoryAxis();
              axis.categoryField = "@axis";
              chart.horizontalAxis = axis;
             
              var seriesArray:Array = new Array();
              var ls:LineSeries = null;
              for (var i:int = 0; i<itemsCount; i++) {
                  var yFieldName:String = "series" + (i+1);
                 
                  ls = new LineSeries();
                  ls.yField = yFieldName;
                  ls.displayName = items.series1[0].@label;   <-- This is the hardcoded line I need to change as the series no. changes on every loop
                  ls.styleName = "lineChartSeries";
                  ls.setStyle("itemRenderer", new ClassFactory(CircleItemRenderer));
                 
                  seriesArray.push(ls);
              }
             
              chart.series = seriesArray;
             
              legend.direction = "horizontal";
          }
         
          legend.dataProvider = chart;
         
          DataCharts.addChildAt(chart, 1);
          DataCharts.addChildAt(legend, 2);
      }