0

I created a BorderPane and put a Group container in Center position. Inside the group container I added a LineChart and a circle. I fill my LineChart with a File and it is correctly filled. I want to get the displayPosition of the nodes of my LineChart but when I apply the method getDisplayPosition I get a 0.

I've donde this in a prevoius project and it worked just fine but the diference is this time I am using SceneBuilder and it is not working

public class FXMLDocumentController implements Initializable {

    @FXML
    private LineChart<Float,Float> chartPrincipal;
    @FXML
    private NumberAxis yAxis;
    @FXML
    private NumberAxis xAxis;
    @FXML
    private Circle circle;

    @Override
    public void initialize(URL url, ResourceBundle rb) {
        XYChart.Series seriePrincipal = new XYChart.Series();        
        seriePrincipal.setName("Distance/Altitude");

        ArrayList<Double> distance = new ArrayList<Double>(); //xAxis
        ArrayList<Double> altitude = new ArrayList<Double>(); //yAxis

        File distanceFile = new File("distance.txt");
        File altitudeFile = new File("altitude.txt");

        //fileToList is a method I did to fill the ArrayList, nothing unusual here
        distance= fileToList(distanceFile);
        altitude = fileToList(altitudeFile);

        //adding the values of the arrayList to the series                       
        for(int i=0; i<altitude.size(); i++){
            seriePrincipal.getData().add(new XYChart.Data(distance.get(i),altitude.get(i)));           
        }

        //filling lineChart with the serie                                                  
        chartPrincipal.getData().add(seriePrincipal);     

        chartPrincipal.setCreateSymbols(false);

        //I added this "for" cycle to get the display position of every node in the lineChart                     
        for(int i=0;i<distance.size();i++){
            System.out.println(distance.get(i)+","+altitude.get(i));
            System.out.println(xAxis.getDisplayPosition(distance.get(i))+", "+ yAxis.getDisplayPosition(altitude.get(i)));
        }  

    }
}

Note: What I intend to do is get the display position and create a polyline with those values, then a PathTransition with the polyline and make the circle the node of the PathTransition that will do the transition, so it looks like the circle is going through the LineChart. Again, I've done this before and worked, but this time I'm using SceneBuilder and it is not working

GAlexMES
  • 335
  • 2
  • 20
davigzzz
  • 134
  • 1
  • 12

0 Answers0