2014-10-17 2 views
1

GWT를 사용하여 메소드를 호출 할 수있을 때 구성 요소가 DOM에 첨부 된 후 플롯팅의 색상이 고정 되었습니까? 어떤 처리기를 적시에 구현해야합니까?gFlot GWT의 DOM에 부착 된 경우

편집 : 실제 상황은 같은 (부사장이 VerticalPanel입니다)입니다 :

   plot=createPlotGraph(); 
       if (plot!=null){ 
        plot.setSize("100%","100%"); 
        vp.add(plot); 
        vp.setCellHeight(plot, "100%");      

        plot.addAttachHandler(new AttachEvent.Handler() { 

         @Override 
         public void onAttachOrDetach(AttachEvent event) { 
          plot.getModel().getSeries().get(0).getAutoGeneratedColor() 
          System.out.println(plot.getModel().getSeries().length()); 
          System.out.println(plot.getModel().getSeries().get(0).getColor()); 

         } 
        }); 
       } 

나는 내가 화면의 모든 확인 참조, 실제로는 제대로 렌더링되는 3 개 (또는 그 이상)의 시리즈가 발견 , println에 의해 적어지는 색은 항상 null입니다.

다른 시도 :

 if (plot!=null){ 
        plot.setSize("100%","100%"); 



        plot.addAttachHandler(new AttachEvent.Handler() { 

         @Override 
         public void onAttachOrDetach(AttachEvent event) { 

          System.out.println(plot.getModel().getSeries().length()); 
          System.out.println(plot.getModel().getSeries().get(0).getColor()); 

         } 
        }); 



        vp.add(plot); 
        vp.setCellHeight(plot, "100%"); 

       } 

같은 결과

갱신, 다른 시도 :

 plot.setSize("100%","100%"); 



        plot.addAttachHandler(new AttachEvent.Handler() { 

         @Override 
         public void onAttachOrDetach(AttachEvent event) { 

          Scheduler.get().scheduleDeferred(new ScheduledCommand() { 
           @Override 
           public void execute() { 
            System.out.println(plot.getModel().getSeries().length()); 
            System.out.println(plot.getModel().getSeries().get(0).getColor()); 
           } 
          });        
         } 
        }); 

같은 결과 ... 널

+0

첨부 처리기를 추가하고 플롯을 추가해야합니다. 그렇지 않으면 처리 할 핸들러를 추가하기 전에'AttachEvent'가 실행될 가능성이 있습니다 ... –

+0

편집 결과에서 볼 수있는 방법을 시도했습니다 ... 동일한 결과 3 개, null 색상 –

+0

내 업데이트 된 답변을 참조하십시오. –

답변

0
gFlot 포럼에서 직접

실제 솔루션 :

plot.getPlot().getData().get(n).getString("color") 

시리즈는 직접 사용하지만, 복사 및 색상이 원래 설정되어 있지 않습니다되지 않습니다!

희망은 다른 사람에게 유용 할 수 있습니다.

0

당신은 AttachEvent.Handler 당신의 Widget에 추가한다 :

widget.addAttachHandler(new AttachEvent.Handler() { 
    @Override 
    public void onAttachOrDetach(AttachEvent event) { 
     if (event.isAttached()) { 
      // Widget got attached to DOM 
     } else { 
      // Detached 
     } 
    } 
}); 

JSNI 래퍼 값 (이 경우 gflot)에 액세스 할 때 문제가 발생하면 일반적으로 ScheduledCommand에있는 호출을 래핑하는 데 도움이됩니다. 이렇게하면 브라우저 이벤트 루프가 반환 된 후 명령이 실행되도록 할 수 있습니다. 그러면 래퍼가 DOM에서 제대로 초기화되어야합니다.

Scheduler.get().scheduleDeferred(new ScheduledCommand() { 
    @Override 
    public void execute() { 
     System.out.println(plot.getModel().getSeries().length()); 
     System.out.println(plot.getModel().getSeries().get(0).getColor()); 
    } 
}); 
+0

위젯을 사용하면 이미 시도한 gflot 인스턴스를 의미하지만 .... 결과로 null이 있습니다 –

+0

자세한 내용을 제공 할 수 있습니까? 너 뭐 해봤 니? https://github.com/nmorel/gflot/wiki의 지침을 따랐습니까? –

+0

글쎄, 외부 이벤트 (버튼 이벤트)에서 내 골프의 컨테이너 인 GWT SimplePanel이 있습니다. 기본적으로 sequenze는 다음과 같습니다 : button -> gflot creation ---> gflot 객체에 제안한 이벤트 핸들러를 추가하고 이벤트 시리즈 color ...에서 null을 얻습니다. –

관련 문제