title: How to zoom-out javafx linechart after it was zoomed in?
body: <p>I've got this code right now.</p>
  
  <pre><code>public class ScalableChart extends VBox implements Initializable{
      @FXML
      private LineChart&lt;Number, Number&gt; chart;
      @FXML
      private Rectangle zoomRect;
      @FXML
      private StackPane pane;
  
      private boolean selectionGestureStarted = false;
  
      private ObjectProperty&lt;javafx.geometry.Point2D&gt; mouseAnchor = new SimpleObjectProperty&lt;&gt;();;
      public ScalableChart() {
          FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource(
                  "hello.fxml"));
          fxmlLoader.setRoot(this);
          fxmlLoader.setController(this);
  
          try {
              fxmlLoader.load();
              zoomRect.setManaged(true);
          } catch (IOException exception) {
              throw new RuntimeException(exception);
          }
  
      }
  
      @FXML
      protected void reset(MouseEvent event) {
          System.out.println("Reset");
          chart.getXAxis().setAutoRanging(true);
          chart.getYAxis().setAutoRanging(true);
          final NumberAxis xAxis = (NumberAxis)chart.getXAxis();
          xAxis.setLowerBound(0);
          xAxis.invalidateRange(chart.getData().);
          xAxis.setUpperBound(Collections.max(chart.getData().));
          final NumberAxis yAxis = (NumberAxis)chart.getYAxis();
          yAxis.setLowerBound(0);
          yAxis.setUpperBound(1000);
  
          zoomRect.setWidth(0);
          zoomRect.setHeight(0);
      }
  
      @FXML
      protected void startSettingZoom(MouseEvent event) {
          setSelectionGestureStarted(true);
          mouseAnchor.set(new javafx.geometry.Point2D(event.getX(), event.getY()));
          zoomRect.setWidth(0);
          zoomRect.setHeight(0);
      }
  
      @FXML
      protected void changeZoomSettings(MouseEvent event) {
          if (isSelectionGestureStarted()) {
              zoomRect.setX(Math.min(event.getX(), mouseAnchor.get().getX()));
              zoomRect.setY(Math.min(event.getY(), mouseAnchor.get().getY()));
              zoomRect.setWidth(Math.abs(event.getX() - mouseAnchor.get().getX()));
              zoomRect.setHeight(Math.abs(event.getY() - mouseAnchor.get().getY()));
          }
  
      }
  
      @FXML
      protected void stopSettingZoom(MouseEvent event) {
          chart.getXAxis().setAutoRanging(false);
          chart.getYAxis().setAutoRanging(false);
          doZoom(zoomRect, chart);
          zoomRect.setWidth(0);
          zoomRect.setHeight(0);
          setSelectionGestureStarted(false);
      }
  
  
      private void doZoom(javafx.scene.shape.Rectangle zoomRect, LineChart&lt;Number, Number&gt; chart) {
          javafx.geometry.Point2D zoomTopLeft = new javafx.geometry.Point2D(zoomRect.getX(), zoomRect.getY());
          javafx.geometry.Point2D zoomBottomRight = new javafx.geometry.Point2D(zoomRect.getX() + zoomRect.getWidth(), zoomRect.getY() + zoomRect.getHeight());
          final NumberAxis yAxis = (NumberAxis) chart.getYAxis();
          javafx.geometry.Point2D yAxisInScene = yAxis.localToScene(0, 0);
          final NumberAxis xAxis = (NumberAxis) chart.getXAxis();
          javafx.geometry.Point2D xAxisInScene = xAxis.localToScene(0, 0);
          double xOffset = zoomTopLeft.getX() - yAxisInScene.getX() ;
          double yOffset = zoomBottomRight.getY() - xAxisInScene.getY();
          double xAxisScale = xAxis.getScale();
          double yAxisScale = yAxis.getScale();
          xAxis.setLowerBound(xAxis.getLowerBound() + xOffset / xAxisScale);
          xAxis.setUpperBound(xAxis.getLowerBound() + zoomRect.getWidth() / xAxisScale);
          yAxis.setLowerBound(yAxis.getLowerBound() + yOffset / yAxisScale);
          yAxis.setUpperBound(yAxis.getLowerBound() - zoomRect.getHeight() / yAxisScale);
          System.out.println(yAxis.getLowerBound() + " " + yAxis.getUpperBound());
          zoomRect.setWidth(0);
          zoomRect.setHeight(0);
      }
  
      @Override
      public void initialize(URL url, ResourceBundle resourceBundle) {
  
          chart.setTitle("Title");
          LineChart.Series&lt;Number, Number&gt; series = new LineChart.Series&lt;Number, Number&gt;();
          series.getData().add(new XYChart.Data&lt;Number, Number&gt;(10, 10));
          series.getData().add(new XYChart.Data&lt;Number, Number&gt;(20, 20));
          chart.getData().add(series);
      }
  
      public boolean isSelectionGestureStarted() {
          return selectionGestureStarted;
      }
  
      public void setSelectionGestureStarted(boolean selectionGestureStarted) {
          this.selectionGestureStarted = selectionGestureStarted;
      }
  }
  </code></pre>
  
  <p>Also right now I can't see selection rectangle when it's on chart. I'm using the stackpane and I tried to add rectangle before the chart and also after the chart. None of this is working.</p>