views:

171

answers:

1

Dear all,

I want draw a chart based on the date retrieve from the database by using RPC.

But everytime I fail to get the result. My rpc function is working.

I think is the sequence of the process.

below is my class:

public class TrafficPattern_1 extends GChart {


        TrafficPattern_1() {

        final DBServiceAsync dbService = GWT
        .create(DBService.class);

        dbService.SendData(null, null,
                new AsyncCallback<Container_TrafficPattern>() {

                    @Override
                    public void onFailure(Throwable caught) {

                    }

                    @Override
                    public void onSuccess(Container_TrafficPattern result) {
                        // TODO Auto-generated method stub

                        pContainer.SetaDate(result.aDate.get(1));
                    }
                }); 

        pContainer.aDate.get(0);
     setChartSize(350, 200); 
         setChartTitle("<h2>Temperature vs Time<h2>");
         setPadding("8px");
         //setPixelSize(380, 200);

         getXAxis().setAxisLabel("<small><b><i>Time</i></b></small>");
         getXAxis().setHasGridlines(true);
         getXAxis().setTickCount(6);
         // Except for "=(Date)", a standard GWT DateTimeFormat string
         getXAxis().setTickLabelFormat("=(Date)h:mm a");

         getYAxis().setAxisLabel("<small><b><i>&deg;C</i></b></small>");
         getYAxis().setHasGridlines(true);
         getYAxis().setTickCount(11);
         getYAxis().setAxisMin(11);
         getYAxis().setAxisMax(16);

         addCurve();
         getCurve().setLegendLabel("<i> </i>");
         getCurve().getSymbol().setBorderColor("blue");
         getCurve().getSymbol().setBackgroundColor("blue");
        // getCurve().getSymbol().setFillSpacing(10);
        // getCurve().getSymbol().setFillThickness(3);

         getCurve().getSymbol().setSymbolType(SymbolType.LINE);
         getCurve().getSymbol().setFillThickness(2);
         getCurve().getSymbol().setFillSpacing(1);

         for (int i = 0; i < dateSequence.length; i++)
           // Note that getTime() returns milliseconds since
           // 1/1/70--required whenever "date cast" tick label
           // formats (those beginning with "=(Date)") are used.
           getCurve().addPoint(dateSequence[i].date.getTime(),
                               dateSequence[i].value);
   }
+2  A: 

Since GWT RPC is asynchronous, you don't know if or when it will succeed. And more relevant to your code since GWT RPC is an asynchronous callback mechanism, its not like synchronous or procedural execution in the linear sense that "pContainer.SetaDate(result.aDate.get(1));" would execute before "pContainer.aDate.get(0);" Rather than setting a date property on pContainer with successful result of your callback, pass it as a parameter to an new method that generates the content of your chart. Simply refactor out everything after your callback as this new method and call it on success, passing it the date as an arg.

Chromehead