2016-08-12 2 views
0

Matlab의 GUI를 JavaFX 8 애플릿으로 변환하려고합니다. 아래 그림과 같이 이미지에 플롯이있는 산점도가 필요합니다. CIE의도의 화상 위에서 보듯이미지에 산점도를 그리는 방법은 무엇입니까?

Example of desired scatter plot

는 산점도 통합된다. stackpane을 사용해 보았지만 그 위에 이미지가있을 때 플롯이 보이지 않습니다. 당신은이 작업을 수행하지 않아도됩니다

class SuperScatterChart extends ScatterChart{ 

     public SuperScatterChart(Axis arg0, Axis arg1) { 
      super(arg0, arg1); 
      // TODO Auto-generated constructor stub 
     } 




     @Override 
     protected void layoutPlotChildren(){ 

      ImageView iv1 = new ImageView(new Image("file:///C:/Desktop/cie.png",450,450,true,true)); 
      // How do I add iv1 to plot children? 
      super.layoutPlotChildren(); 

     } 



    } 
+0

두 가지 접근 방식이 떠오 릅니다. 1. CSS를 사용하십시오 : ['.chart-plot-background' 노드] (http://docs.oracle.com/javase/8/javafx/api/javafx/scene/doc-files/cssref.html#xychart) 는 ['Region'] (http://docs.oracle.com/javase/8/javafx/api/javafx/scene/doc-files/cssref.html#region)이므로'-fx- background-image'를 CSS에 추가했습니다. 2. ScatterChart를 서브 클래스 화하고 layoutPlotChildren()을 오버라이드하여 이미지를 플롯 영역에 추가 한 다음, scatter.point를 추가하기 전에 super.layoutPlotChildren()을 호출하십시오. 조금 비슷한 것이 있으면 http://stackoverflow.com/questions/38871202를 참조하십시오. –

+0

또한 : "스택 판을 사용해 보았습니다.하지만 이미지가 위에 표시되면 플롯이 보이지 않습니다." - 이미지를 스택 전의 * 차트 앞에 추가하면 그 일이 일어나지 않습니다. –

+0

그러나 첫 번째 방법을 시도했지만 이미지는 분산 형 차트 뒤에 있습니다. 두 번째 방법은 덮어 쓰기 된 layoutPlotChildren()에서 이미지를 그림 영역으로 변경하는 코드 구문은 무엇입니까? Thanks @James_D – hfz

답변

0

당신은

getPlotChildren().add(iv1); 

와 플롯 아이들에게 이미지보기를 추가 : layoutplotchildren()를 재정의하려고

편집 -

layoutPlotChildren() 메서드를 재정의했습니다. 생성자에서 한 번 수행하면 충분할 수 있습니다.

class SuperScatterChart extends ScatterChart<Number, Number>{ 

    private final ImageView iv1 ; 

    public SuperScatterChart(NumberAxis xAxis, NumberAxis yAxis) { 
     super(xAxis, yAxis); 
     iv1 = new ImageView(new Image("file:///C:/Desktop/cie.png",450,450,true,true)); 
     getPlotChildren().add(iv1); 
    } 

} 

이미지가 기본 위치에 배치됩니다 (플롯 영역이 기본 레이아웃을 수행하지 않으므로 왼쪽 상단에 배치됩니다). 당신이 그것을 이동해야하는 경우, 대신 픽셀 기반의 좌표계의이 당신에게 쉽게 차트 축 좌표계 즉, "줄거리 좌표"를 사용하여 이미지를 배치 할 수있는 기회를 제공

@Override 
protected void layoutPlotChildren() { 
    double x = ... ; // x coordinate of image in xAxis coordinates 
    double y = ... ; // y coordinate of image in yAxis coordinates 

    double layoutX = getXAxis().getDisplayPosition(x); 
    double layoutY = getYAxis().getDisplayPosition(y); 

    iv1.setLayoutX(layoutX); 
    iv1.setLayoutY(layoutY); 

    super.layoutPlotChildren(); 
} 

메모를 추가 .

+0

고마워! 오랫동안 이것을 알아 내려고 노력했습니다. @James_D – hfz

관련 문제