Как передать значение в линейном графике в flex, из базы данных, где я использую Java для передачи значения - PullRequest
0 голосов
/ 29 декабря 2011

Я использую трендовые линии из графиков.Я использую Java и передаю значения из базы данных Uins Blazeds [??].Я беру коллекцию массивов, чтобы извлечь значения из базы данных и поместить ее в линии тренда.Так в чем же ошибка в коде и каким должен быть правильный код?

<?xml version="1.0" encoding="utf-8"?>

<!-- This example is made using amStock Flex component. Visit http://flex.amcharts.com to see more examples -->

<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"
               xmlns:amcharts="http://www.amcharts.com/com_internal"
               backgroundColor="#FFFFFF"
               width="100%" height="100%"
               creationComplete="init()"
               viewSourceURL="srcview/index.html">


    <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->




        <mx:Producer id="producer" destination="RandomDataPush1"
                     acknowledge="ack(event)" fault="handleFault(event)"/> 
        <mx:Consumer id="consumer" destination="RandomDataPush1"
                     message="messageHandler(event)" fault="handleFault(event)" /> 
    </fx:Declarations>

    <fx:Script>
        <![CDATA[
            import mx.collections.ArrayCollection;
            import com.amcharts.events.SerialChartEvent;
            import mx.controls.Alert;
            import mx.core.FlexGlobals;
            import mx.messaging.events.MessageAckEvent;
            import mx.messaging.events.MessageEvent;
            import mx.messaging.events.MessageFaultEvent;
            import mx.messaging.messages.AsyncMessage;
            import mx.rpc.events.ResultEvent;

            private var dataString:String =

            [Bindable]
            private var chartData:ArrayCollection = new ArrayCollection();

            /*  private function generateChartData():void
            {
                var firstDate:Date = new Date();
                firstDate.setMinutes(firstDate.getMinutes() - 2000);

                for(var i:Number = 0; i < 2000; i++)
                {
                    var newDate:Z = new Date(firstDate);

                    newDate.setMinutes(newDate.getMinutes() + i);

                    var a:Number = Math.round(Math.random() * (40 + i)) + 100 + i;
                    var b:Number   = Math.round(Math.random() * (1000 + i)) + 500 + i * 2;

                    chartData.addItem({date:newDate, a:a, b:b});
                }
            }  */
            private var Bindable:Object;
            private function parseData():void{
                // parse data string
                var rowArray:Array = dataString.split("\n");
                for(var i:uint = 0; i < rowArray.length; i++){
                    var row:Array = rowArray[i].split(",");
                    var dateArray:Array = row[0].split("-");
                    var date:Date = new Date(Number(dateArray[0]), Number(dateArray[1]) - 1, Number(dateArray[2]));
                    var open:Number = row[1];
                    var high:Number = row[2];
                    var low:Number = row[3];
                    var close:Number = row[4];

                    //chartData.addItem({date:date, open:open, high:high, low:low, close:close});
                }
            }

                private function onClose():void
                {
                    var msg:AsyncMessage = new AsyncMessage(); 
                    msg.body = "Close"; 

                    //msg.headers["symbol"]="IBKR";
                    msg.headers["symbol"]="EUR";
                    producer.send(msg); 
                    consumer.subscribe();
                    //PopUpManager.removePopUp(this);

                }

                public function init():void { 
                    //  Alert.show("Hi from init..");
                    var msg:AsyncMessage = new AsyncMessage(); 
                    msg.body = "New"; 

                    //msg.headers["symbol"]="IBKR";
                    msg.headers["symbol"]="EUR";
                    producer.send(msg); 
                    consumer.subscribe();

                    var ar:ArrayCollection=new ArrayCollection();
                    ar.addItemAt("EUR",0);
                    //pair_chart.dataProvider=ar;
                    //pair_chart.selectedIndex=0;

                    var ar1:ArrayCollection=new ArrayCollection();
                    ar1.addItemAt("Candle",0);
                    ar1.addItemAt("Bar",1);


                }
                private function ack(event:MessageAckEvent):void 
                { 
                    //Alert.show(""+event.message.body);
                    chart.dataProvider = event.message.body as ArrayCollection;
                    //mybarChart.dataProvider = event.message.body as ArrayCollection;

                }
                private function handleFault(event:MessageFaultEvent):void 
                { 
                    Alert.show("fault"+event.faultString); 
                } 

                private function messageHandler(event:MessageEvent):void 
                { 

                    var dateTime:Date = new Date();
                    var obj:Object = new Object(); 


                    //Alert.show("hi "+event.message.body);

                    //obj.time = format.format(new Date()).toString();
                    //chart.dataProvider = event.message.body as ArrayCollection;

                    //FlexGlobals.topLevelApplication.crntpos.ui.chartArrCollection.addAll(event.message.body as ArrayCollection);
                    chartData.addAll(event.message.body as ArrayCollection);
                    //Alert.show("chartData.length "+chartData.length);
                    chart.dataProvider = chartData; 
                    //Alert.show("hi "+chartData.list);
                    //mybarChart.dataProvider=FlexGlobals.topLevelApplication.crntpos.ui.chartArrCollection;
                }
        ]]>

    </fx:Script>

    <s:VGroup width="100%" height="100%" paddingBottom="10" paddingTop="10" paddingLeft="10" paddingRight="10">

        <amcharts:AmStockChart width="100%" height="100%">
            <amcharts:dataSets>
                <amcharts:DataSet id="chart" color="#00CC00" dataProvider="{chartData}" categoryField="date" title="First data set">
                    <amcharts:fieldMappings>
                        <amcharts:FieldMapping fromField="a" toField="value"/>
                        <amcharts:FieldMapping fromField="b" toField="volume"/>
                    </amcharts:fieldMappings>
                </amcharts:DataSet>
            </amcharts:dataSets>

            <amcharts:panels>
                <!-- to enabled drawing icons, you only need to set drawingIconsEnabled="true" on StockPanel -->
                <amcharts:StockPanel drawingIconsEnabled="true" title="Value" height="50%" showCategoryAxis="true">
                    <amcharts:stockGraphs>
                        <amcharts:StockGraph bulletBorderColor="#FFFFFF" bullet="round" id="g1" valueField="value" compareField="value" comparable="true"/>
                    </amcharts:stockGraphs>
                    <amcharts:stockLegend>
                        <amcharts:StockLegend/>
                    </amcharts:stockLegend>
                </amcharts:StockPanel>
            </amcharts:panels>

            <amcharts:periodSelector>
                <amcharts:PeriodSelector position="bottom" width="157">
                    <amcharts:periods>
                        <amcharts:PeriodButton selected="true" label="1 Hour" period="hh" count="1"/>
                        <amcharts:PeriodButton label="2 Hours" period="hh" count="2"/>
                        <amcharts:PeriodButton label="6 Hours" period="hh" count="6"/>
                        <amcharts:PeriodButton label="1 Day" period="DD" count="1"/>
                        <amcharts:PeriodButton label="MAX" period="MAX"/>
                    </amcharts:periods>
                </amcharts:PeriodSelector>
            </amcharts:periodSelector>

            <amcharts:chartScrollbarSettings>
                <amcharts:ChartScrollbarSettings height="30" graph="{g1}"/>
            </amcharts:chartScrollbarSettings>

            <amcharts:categoryAxesSettings>
                <amcharts:CategoryAxesSettings minPeriod="mm"/>
            </amcharts:categoryAxesSettings>

            <amcharts:chartCursorSettings>
                <amcharts:ChartCursorSettings showValueAxisValue="true" crosshair="true"/>
            </amcharts:chartCursorSettings>         

        </amcharts:AmStockChart>
    </s:VGroup>

</s:Application>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...