<?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()”>
<fx:Declarations>
<mx:HTTPService id=“srv” resultFormat=“text” useProxy=“false” result=“resultDatas(event)” />
<!– K线图 上涨下跌2种样式 –>
<mx:SolidColor id=“up” color=“red” alpha=“.8″/>
<mx:SolidColor id=“down” color=“green” alpha=“.8″/>
<!– 一些线 –>
<mx:SolidColorStroke id=“line_ma5″ color=“#ff8040″ weight=“0.5″ alpha=“1″/>
<mx:SolidColorStroke id=“line_ma10″ color=“#60A2FF” weight=“0.5″/>
<mx:SolidColorStroke id=“line_ma20″ color=“#ff00ff” weight=“0.5″/>
<mx:SolidColorStroke id=“line_ma30″ color=“#008000″ weight=“0.5″/>
<!– 将非可视元素(例如服务、值对象)放在此处 –>
</fx:Declarations>
<fx:Script>
<![CDATA[
/*
* deflate.mxml
* 作者:偶尔陶醉 blog:www.stutostu.com
* 功能: 模拟股票K线图,向PHP接口调用大量数据
*/
import flash.utils.ByteArray;
import mx.collections.ArrayCollection;
import mx.controls.Alert;
import mx.controls.Label;
import mx.rpc.events.ResultEvent;
import mx.utils.Base64Decoder;
import spark.components.TextArea;
private var str:String;
[Bindable]
private var _myData:ArrayCollection;
private var big:ArrayCollection;
private var page:int=1;
private var allpage:int;
private var start:int = 0;
private function init():void{
this.systemManager.stage.addEventListener(KeyboardEvent.KEY_DOWN ,_keyDownHandler);
srv.url = “http://localhost/test.php”;
srv.send();
}
private function resultDatas(event:ResultEvent):void{
str = event.result.toString();
var base64:Base64Decoder = new Base64Decoder();
base64.decode( str );
var byte:ByteArray = new ByteArray();
byte = base64.toByteArray();
byte.inflate();
var result:String = byte.toString();
var words:Array=result.split(‘;’);
var subwords:Array=[];
allpage = words.length-1;
var max:Number=1;
var min:Number=100000;
big = new ArrayCollection();
Alert.show(“ooxx”);
for(var i:int = 0;i <= allpage;i++)
{
subwords=words[i].split(‘,’);
subwords[0] = subwords[0].substr(0,10);
big.addItem({“Date”: subwords[0], “Open”: Number(subwords[1]), “High”:Number(subwords[2]),
“Low”:Number(subwords[3]),”Close”:Number(subwords[4]),”Vol”:Number(subwords[5]),
“Amount”:subwords[6],”VMa5″:subwords[7],”VMa10″:subwords[8],”VMa20″:subwords[9],
“Ma5″:subwords[10],”Ma10″:subwords[11],”Ma20″:subwords[12],”Ma30″:subwords[13],
“K”:subwords[14],”D”:subwords[15],”J”:subwords[16],”Diff”:subwords[17],
“Dea”:subwords[18],”Macd”:subwords[19]});
}
extrude();
}
public function extrude():void{
page <= 0 ? page = 1 : ”;
var end:int = page*30;
_myData = new ArrayCollection();
for(var i:int=0;i<=end;i++)
{
_myData.addItem( {“Date”: big[i]['Date'], “Open”: big[i]['Open'], “High”:big[i]['High'],
“Low”:big[i]['Low'],”Close”:big[i]['Close'],”Vol”:big[i]['Vol'],
“Amount”:big[i]['Amount'] } );
}
}
protected function _keyDownHandler(event:KeyboardEvent):void{
switch(event.keyCode)
{
case 38:
page–;
extrude();
break;
case 40:
page++;
extrude();
break;
}
}
]]>
</fx:Script>
<mx:CandlestickChart id=“candlestickchart” width=“100%” height=“70%” chromeColor=“#040404″
color=“#FFFFFF” dataProvider=“{_myData}”
paddingLeft=“2″ showDataTips=“false”
textAlign=“right” >
<mx:verticalAxis>
<mx:LinearAxis id=“vaxis” baseAtZero=“false” />
</mx:verticalAxis>
<mx:verticalAxisRenderers>
<mx:AxisRenderer axis=“{vaxis}” placement=“left” labelGap=“0″ >
<mx:axisStroke>
<mx:SolidColorStroke color=“#CCCCCC” weight=“1″ alpha=“0.8″ />
</mx:axisStroke>
</mx:AxisRenderer>
</mx:verticalAxisRenderers>
<mx:horizontalAxis>
<mx:CategoryAxis id=“haxis” categoryField=“Date” />
</mx:horizontalAxis>
<mx:horizontalAxisRenderers>
<mx:AxisRenderer axis=“{haxis}” canDropLabels=“true”>
<mx:axisStroke>
<mx:SolidColorStroke color=“#bbccdd” weight=“1″ alpha=“0.8″/>
</mx:axisStroke>
</mx:AxisRenderer>
</mx:horizontalAxisRenderers>
<mx:series>
<mx:CandlestickSeries id=“main_line”
openField=“Open”
highField=“High”
lowField=“Low”
closeField=“Close”
fill=“{up}”
declineFill=“{down}”
/>
<mx:LineSeries yField=“Ma5″ lineStroke=“{line_ma5}”/>
<mx:LineSeries yField=“Ma10″ lineStroke=“{line_ma10}”/>
<mx:LineSeries yField=“Ma20″ lineStroke=“{line_ma20}”/>
<mx:LineSeries yField=“Ma30″ lineStroke=“{line_ma30}”/>
</mx:series>
</mx:CandlestickChart>
</s:Application>
|