4 Replies Latest reply on Jun 11, 2009 9:34 AM by Gregory Lafrance

    Dynamically creating multiple LineSeries from XML

    ahujadady
      Hi,

      I'm unable to figure out why my chart does not display. My task is to read in an XML file, depending on which multiple line series will be created and displayed on a line chart. (I am using the Flex-Ajax Bridge)

      In my mxml, I have:

      [Bindable]
      public var _elements:XMLList;

      public function createXMLList(data:String):XMLList
      {
      var _xml:XML = new XML(data);
      _elements = _xml.elements();
      return _elements;
      }

      <mx:Panel width="450" height="400" id="panel" >
      <mx:LineChart id="chart" height="350" width="300"
      paddingLeft="5" paddingRight="5"
      showDataTips="true" visible="false"
      dataProvider="{_elements}">
      </mx:LineChart>
      </mx:Panel>

      In my html file, I use the XMLHttpRequest to get my xml and do the
      following:

      function createChart() {
      if (req.readystate == 4 && req.status == 200) {
      var seriesArray = new Array();
      var flexApp = FABridge.example.root();
      var chart = flexApp.getPanel().getChildByName("chart");
      var s = FABridge.example.create("mx.charts.series.LineSeries");
      flexApp.createXMLList(req.responseText);
      s.set("yField", "datapoint");
      seriesArray.push(s);
      chart.setSeries(seriesArray);
      chart.setVisible("true");
      }
      }

      My XML file has the following structure:

      <?xml version="1.0" encoding="utf-8"?>
      <result metricDfn="Price">
      <company1 id="1">
      <datapoint date="Jan">50</datapoint>
      <datapoint date="Feb">60</datapoint>
      <datapoint date="Mar">40</datapoint>
      <datapoint date="Apr">50</datapoint>
      <datapoint date="May">40</datapoint>
      </company1>
      </result>

      Anything obvious that I'm not doing right?