现在我必须在这里遗漏一些东西,因为这似乎是一个非常基本的问题,可以在任何“Flex 图表入门”教程中解决。但是,我所能找到的只是提示图表应在 dataProvider 更改时自动更新。请注意,提示。
这是我的标记:
<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" title="econemon Sensor Simulator">
<!-- ... -->
<mx:Script source="SimulatorFunctions.as" />
<mx:HDividedBox left="0" top="0" bottom="0" right="0">
<!-- ... -->
<mx:VDividedBox width="75%" height="100%">
<mx:PlotChart width="100%" height="33%" dataProvider="{xmlDataTest}">
<mx:horizontalAxis>
<mx:DateTimeAxis dataUnits="seconds" displayLocalTime="true" parseFunction="dtFromUnixtime"/>
</mx:horizontalAxis>
<mx:series>
<mx:LineSeries xField="dt" yField="fltValue" displayName="Testkurve" />
</mx:series>
</mx:PlotChart>
<mx:Panel width="100%" height="66%">
<mx:Button label="Start" click="vDataStart()" />
<mx:Button label="Stop" click="vDataStop()" />
</mx:Panel>
</mx:VDividedBox>
</mx:HDividedBox>
</mx:WindowedApplication>
这是我的 ActionScript 的一部分:
[Bindable]
public var xmlDataTest:Array = [
{ dt: "1230908694", fltValue: "50.4" },
// ...
{ dt: "1230909594", fltValue: "35.4" }
]
public var dflt:Number = 10.0;
public var timData:Timer = new Timer(3000);
// ...
public function vDataStart():void
{
if (!timData.running) {
timData.addEventListener(TimerEvent.TIMER, vAppendDatum);
timData.start();
}
}
public function vDataStop():void
{
if (timData.running) {
timData.stop();
}
}
public function vAppendDatum(evt:Event):void
{
var dtNew:String;
var fltNew:String;
var fltT: Number;
dtNew = String(Number(xmlDataTest[xmlDataTest.length - 1].dt) + 100);
fltT = Number(xmlDataTest[xmlDataTest.length - 1].fltValue);
if (fltT < 10.0 || fltT > 70) {
dflt *= -1;
}
fltNew = String(fltT + dflt);
xmlDataTest.push({ dt: dtNew, fltValue: fltNew });
//trace("Datenpunkte: " + xmlDataTest.length);
}
单击“开始”按钮后,数据数组每 3 秒扩展一次,但屏幕上的图表保持不变。