tags:

views:

183

answers:

1

I have something like this xml data

<data>
<result month="Jan-04">
    <employee id="1">
        <a>81768</a>
        <b>60310</b>
        <c>43357</c>
    </employee>
    <employee id="2">
        <a>81768</a>
        <b>60310</b>
        <te>43357</c>
    </employee>
</result>
<result month="Feb-04">
    <employee id="1">
        <a>81156</a>
        <b>58883</b>
        <c>49280</c>
    </employee>
    <employee id="2">
        <a>81768</a>
        <b>60310</b>
        <c>43357</c>
    </employee>
</result>

I want to display it line chart with month on horizontal axis and a,b,c as series for employee with id==1. The following code doesnt display any data on the chart. Could someone point out the error?

<mx:HTTPService id="srv" url="D:/data.xml" useProxy="false" result="myData=ArrayCollection(srv.lastResult.data.result)"/> 
<mx:Panel title="Line Chart">
 <mx:LineChart id="myChart" 
    showDataTips="true"
  enabled="true" dataProvider="{myData}">
    <mx:horizontalAxis>
       <mx:CategoryAxis categoryField="month"/>
    </mx:horizontalAxis>
    <mx:series>
       <mx:LineSeries yField="employee[0].a" displayName="A" name="a"/>
       <mx:LineSeries yField="employee[0].b" displayName="B" name="b"/>
       <mx:LineSeries yField="employee[0].c" displayName="C" name="c"/>
    </mx:series>
 </mx:LineChart>
 <mx:Legend dataProvider="{myChart}"/>     

A: 

it is very hard to use the xml directly in charts when you have data in more than two level nesting. in the above xml which you have shown, the data is at 3 level nesting. what you have to do is, convert the xml using e4x into two level nesting

e.g

<result month="Jan-04">
    <a empId="1">81768</a>
    <b empId="1">60310</b>
    <c empId="1">43357</c>
    <a empId="2">81768</a>
    <b empId="2">60310</b>
    <c empId="2">43357</c>

either put the original data in this format of transform the result xml in flex to something like shown above then you can easily use it with charts.

Another problem is for your HTTPService resultFormat is object which is default. when the resultformat is object and you pass xml, the hierarchy of objects in the event.result is a bit different than you see in your source xml.

scienty