<?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 Line chart rose down 2 kinds of styles –> <mx:solidcolor id= "Up" color= "Red" alpha= ".8″/>" <mx:solidcolor id= "Down" color= "green" alpha= ".8″/> <!– some lines –> <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″/> <!– places non-visual elements (such as services, value objects) here –> </fx:Declarations> <fx:Script> <! [cdata[ /* * Deflate.mxml * Author: Occasionally intoxicated blog:www.stutostu.com * Function: Simulate stock chart, invoke large amount of data to PHP interface */ 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%" #040404 chromecolor= 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> |