0 Replies Latest reply on May 27, 2007 2:29 PM by romanczar

    LineChart with unknown amount and name of elements

    romanczar
      Hi!
      I want to create a LineChart. This charts displays a changing number over a period of time.

      <?xml version="1.0" encoding="utf-8"?>
      <root>
      <poll>
      <id>1</id>
      <answerIDs>
      <id>a1</id>
      <id>a2</id>
      </answerIDs>
      <resultsByDate>
      <entry date="03/01/2007">
      <1><results>15</results></1>
      <2><results>18</results></2>
      </entry>
      <entry date="03/02/2007">
      <1><results>25</results></1>
      <2><results>8</results></2>
      </entry>
      <entry date="03/03/2007">
      <1><results>45</results></1>
      <2><results>38</results></2>
      </entry>
      </resultsByDate>
      </poll>
      </root>

      <mx:LineChart id="chart" dataProvider="{service.lastResult.root.poll.resultsByDate.entry}" >
      <mx:horizontalAxis>
      <mx:CategoryAxis categoryField="date" />
      </mx:horizontalAxis>
      <mx:horizontalAxisRenderer>
      <mx:AxisRenderer labelRotation="45" />
      </mx:horizontalAxisRenderer>
      <mx:series>
      <mx:LineSeries displayName="1" xField="date" yField="results" />
      <mx:LineSeries displayName="2" xField="date" yField="results" />
      </mx:series>
      </mx:LineChart>


      It only works when I don't use <results> in the XML and set the yField to "1" or "2".


      Later In the application I don't know the amount and name of the elements (1,2,44,4564, ..), so I will use AS for that:

      var ls:LineSeries = new LineSeries();
      chart.series = [ls]; // associate the array

      var answers:Array = ["1", "2"];

      for (var i:uint = 0; i < 2; i++)
      {
      trace(i);
      ls = new LineSeries();
      ls.displayName = answers .toString()
      ls.xField = 'date';
      ls.yField = 'results';
      chart.series
      = ls;
      }


      This code works, but only without 'results'.

      Maybe can someone help me? I sit not possible to have nested objects as provider for xField and yField?