2016-06-25 10 views
1

Ich versuche ein scrollbares Diagramm zu machen, in dem die Y-Achse unabhängig von der Cursorposition in der Bildlaufleiste sichtbar bleibt (standardmäßig, da die Y-Achseninformationen am Ende sind) sehen sie nur aus der Sicht würden Sie, nachdem Sie genug bewegen, das Ende zu sehen)Scrollpanel Liniendiagramm mit fester Ansicht Y-Achse JavaFX

Hier ist ein Beispiel, was im versuchen zu erreichen:

enter image description here

Beachten Sie, dass, obwohl die Bildlaufposition ist auf halbem Wege - Der Y-Achsen-Text (Preis) bleibt weiterhin sichtbar

Ich sah mich im Internet um und konnte nur ein Beispiel für etwas Ähnliches finden, aber es scheint nicht mit einem Liniendiagramm im scrollPane zu funktionieren.

Always visible when scrolled anchored Node in Java FX 2.0?

Die oben genannten Arbeiten mit einem Kreis Objekt, sondern auf ein Liniendiagramm zu ändern wird in Folge „Ausnahme: Ein Grenzwert nicht eingestellt werden kann“, wie es das Layout Rufaufbau scheint automatisch, wenn innerhalb eines Liniendiagramm mit scrollpane

public class FancyScrollPane extends Application { 
private LineChart<String, Number> qChart; 
@Override 
public void start(Stage primaryStage) { 
    ScrollPane scrollPane = new ScrollPane(); 
    Pane content = new Pane(); 
    final CategoryAxis xAxis = new CategoryAxis(); 
    final NumberAxis yAxis = new NumberAxis(12, 20, 1); 
    yAxis.setSide(Side.RIGHT); 
    qChart=new LineChart<String,Number>(xAxis, yAxis); 
    qChart.setPrefSize(3000, 250); 
    content.getChildren().add(qChart); 
    scrollPane.setContent(content); 


    Circle immovableObject = new Circle(30, Color.RED); 
    content.getChildren().add(immovableObject); 

    primaryStage.setScene(new Scene(scrollPane, 300, 300)); 
    primaryStage.show(); 

    yAxis.layoutXProperty().bind(
      scrollPane.hvalueProperty() 
       .multiply(
        content.widthProperty() 
         .subtract(
          new ScrollPaneViewPortWidthBinding(scrollPane)))); 
} 

// we need this class because Bounds object doesn't support binding 
private static class ScrollPaneViewPortWidthBinding extends DoubleBinding { 

    private final ScrollPane root; 

    public ScrollPaneViewPortWidthBinding(ScrollPane root) { 
     this.root = root; 
     super.bind(root.viewportBoundsProperty()); 
    } 

    @Override 
    protected double computeValue() { 
     return root.getViewportBounds().getWidth(); 
    } 
} 

public static void main(String[] args) { launch(); } 
} 

Irgendwelche Ideen rund um das oben genannte Problem oder eine bessere Art und Weise zu bekommen, dies zu erreichen?

Dank

Antwort

0

Hier ist eine kleine Änderung, die die yAchse und den Kreis mit der Bildlaufleiste bewegt die setTranslateX Methode anstelle der layoutXProperty verwenden.

import javafx.application.Application; 
import javafx.beans.binding.DoubleBinding; 
import javafx.scene.Scene; 
import javafx.scene.control.ScrollPane; 
import javafx.scene.layout.Pane; 
import javafx.scene.paint.Color; 
import javafx.scene.shape.Circle; 
import javafx.scene.shape.Rectangle; 
import javafx.stage.Stage; 

public class FancyScrollPane extends Application { 

    @Override 
    public void start(Stage primaryStage) { 
     ScrollPane scrollPane = new ScrollPane(); 
     Pane content = new Pane(); 
     scrollPane.setContent(content); 

     // adding background 
     content.getChildren().add(new Rectangle(500, 500, Color.GREEN)); 

     Circle immovableObject = new Circle(30, Color.RED); 
     content.getChildren().add(immovableObject); 

     primaryStage.setScene(new Scene(scrollPane, 300, 300)); 
     primaryStage.show(); 

     immovableObject.layoutXProperty().bind(
       scrollPane.hvalueProperty() 
         .multiply(
           content.widthProperty() 
             .subtract(
               new ScrollPaneViewPortWidthBinding(scrollPane)))); 
    } 

    // we need this class because Bounds object doesn't support binding 
    private static class ScrollPaneViewPortHeightBinding extends DoubleBinding { 

     private final ScrollPane root; 

     public ScrollPaneViewPortHeightBinding(ScrollPane root) { 
      this.root = root; 
      super.bind(root.viewportBoundsProperty()); 
     } 

     @Override 
     protected double computeValue() { 
      return root.getViewportBounds().getHeight(); 
     } 
    } 
    // we need this class because Bounds object doesn't support binding 
    private static class ScrollPaneViewPortWidthBinding extends DoubleBinding { 

     private final ScrollPane root; 

     public ScrollPaneViewPortWidthBinding(ScrollPane root) { 
      this.root = root; 
      super.bind(root.viewportBoundsProperty()); 
     } 

     @Override 
     protected double computeValue() { 
      return root.getViewportBounds().getWidth(); 
     } 
    } 
    public static void main(String[] args) { launch(); } 
}