I'm trying to get the x,y of a point on a LineChart<Number, Number>
so that I can add a Line
onto it. So I tried to get the x-value of 9 for example by doing:
Group root = new Group();
NumberAxis xAxis = new NumberAxis();
xAxis.setAutoRanging(false);
xAxis.setLowerBound(0);
xAxis.setUpperBound(9);
LineChart<Number, Number> lineChart = new LineChart<Number, Number>(xAxis, yAxis);
System.out.println(xAxis.getDisplayPosition(9)); // 0
root.getChildren().add(lineChart);
Scene scene = new Scene(root, 800, 800);
stage.setScene(scene);
stage.show();
After looking around on the internet I came across a supposed solution
Node chartPlotArea = lineChart.lookup(".chart-plot-background");
double chartZeroX = chartPlotArea.getLayoutX();
System.out.println(xAxis.getDisplayPosition(9) + chartZeroX);
Which also ended up outputting 0
, why does this happen? How can I get the display position of the x,y so that I can pass that into Line.setStartX(...)
/Line.setStartY(...)
?