这是MXML代码。
<?xml version="1.0"?>
<!-- charts/XMLFileDataProvider.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" >
<mx:Model id="results" source="data.xml"/>
<mx:Panel title="Line Chart">
<mx:LineChart id="myChart" dataProvider="{results.result}" showDataTips="true" width="600" height="240">
<mx:horizontalAxis>
<mx:CategoryAxis categoryField="month"/>
</mx:horizontalAxis>
<mx:series>
<mx:LineSeries yField="banana" displayName="Banana"/>
<mx:LineSeries yField="apple" displayName="Apple"/>
<mx:LineSeries yField="orange" displayName="Orange"/>
</mx:series>
</mx:LineChart>
<mx:Legend dataProvider="{myChart}"/>
</mx:Panel>
</mx:Application>
当我更改xml文件中的数据时,更改不会反映在图表中。任何人都可以告诉我我的错误在哪里
这里是xml文件
<data>
<result month="Jan-04">
<apple>81768</apple>
<orange>60310</orange>
<banana>43357</banana>
</result>
<result month="Feb-04">
<apple>81156</apple>
<orange>58883</orange>
<banana>49280</banana>
</data>
答案 0 :(得分:0)
这可能对您有所帮助,我已经创建了关于HTTPService的示例: -
您可以根据上述评论为您提出问题。
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"
creationComplete="init();switchImage()">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
<!--<fx:Model id="results" />-->
<s:HTTPService id="results" result="resultHandler(event)" fault="{trace('Fault')}" />
</fx:Declarations>
<fx:Script>
<![CDATA[
import mx.rpc.events.ResultEvent;
private function init():void
{
var timer:Timer = new Timer(2000);
timer.addEventListener(TimerEvent.TIMER, switchImage);
timer.start();
}
private function switchImage(event:TimerEvent = null):void
{
//url as external URL outside of project folder
results.url = "C:/data/data.xml";
results.send();
}
private function resultHandler(event:ResultEvent):void
{
myChart.dataProvider = null;
myChart.dataProvider = event.result.data.result;
}
]]>
</fx:Script>
<mx:Panel title="Line Chart">
<mx:LineChart id="myChart" showDataTips="true" width="600" height="240">
<mx:horizontalAxis>
<mx:CategoryAxis categoryField="month"/>
</mx:horizontalAxis>
<mx:series>
<mx:LineSeries yField="banana" displayName="Banana"/>
<mx:LineSeries yField="apple" displayName="Apple"/>
<mx:LineSeries yField="orange" displayName="Orange"/>
</mx:series>
</mx:LineChart>
<mx:Legend dataProvider="{myChart}"/>
</mx:Panel>
</s:Application>