我有像这样的xml数据
<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>
我希望在水平轴上显示带月份的折线图,并为id == 1的员工显示a,b,c作为系列。以下代码不显示图表上的任何数据。有人可以指出错误吗?
<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}"/>
答案 0 :(得分:0)
当您有两个以上级别的嵌套数据时,很难直接在图表中使用xml。在您显示的上述xml中,数据处于3级嵌套。你要做的是,使用e4x将xml转换为两级嵌套
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>
要么将原始数据放在这种格式中,将结果xml转换为如上所示的结果,那么您可以轻松地将其与图表一起使用。
另一个问题是你的HTTPService resultFormat是默认的对象。当resultformat是object并且你传递xml时,event.result中对象的层次结构与你在源xml中看到的有点不同。