.mxml文件
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="initApp()">
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
[Bindable]
//为LineChart 定义变量,用来存储LineChart的数据源
private var gprsAC:ArrayCollection = new ArrayCollection();
private static const MINISECENDS:int=1000;
//初始页面时执行
private function initApp():void
{
setInterval(addArr,MINISECENDS)//设置参数1,要执行的方法;参数2,频率大小,以毫秒为单位
}
private var i:Number = 1;
private var tmp_obj:Object;
private function addArr():void
{
tmp_obj = new Object();
var temp_count:Number = Math.ceil(Math.random()*100);
//Math.ceil取该数中整数的部分,如果后面带有小数,向上加1,若是整数,直接取整.如2.3则为3,4.0则为4
//Math.randow生成的随机数,范围在0与1之间.
tmp_obj["time"]=i;
tmp_obj["count"]=temp_count;
gprsAC.addItem(tmp_obj);
i++;
if(i==24)
{
i = 1;
}
}
]]>
</mx:Script>
<mx:LineChart id="linchart" color="#333399" width="100%" height="100%" dataProvider="{gprsAC}"
showDataTips="true" fontSize="12" y="77" x="10">
<mx:horizontalAxis>
<mx:CategoryAxis categoryField="time"/>
</mx:horizontalAxis>
<mx:backgroundElements>
<mx:GridLines direction="horizontal">
<mx:horizontalStroke>
<mx:Stroke weight="1.5" color="#333399" alpha="0.2"/>
</mx:horizontalStroke>
</mx:GridLines>
</mx:backgroundElements>
<mx:series>
<mx:LineSeries id="lineserie" width="160" yField="count"/></mx:series></mx:LineChart>
</mx:Application>