To convert chart values ββto pixels, you can use the NumberAxis#getDisplayPosition() method, which returns the actual coordinates of the chart nodes.
Although these coordinates relate to the area of ββthe diagram, which you can recognize by the following code:
Node chartArea = chart.lookup(".chart-plot-background"); Bounds chartAreaBounds = chartArea.localToScene(chartArea.getBoundsInLocal());
Note localToScene() method that allows you to convert any coordinates to Scene. This way you can use them to update the coordinates of the value marker. Make sure you make a call to localToScene after your scene has been shown.
See the sample program below, which creates the following diagram:

public class LineChartValueMarker extends Application { private Line valueMarker = new Line(); private XYChart.Series<Number, Number> series = new XYChart.Series<>(); private NumberAxis yAxis; private double yShift; private void updateMarker() {
Sergey Grinev
source share