How to add text on horizontal line with JavaFX BarChart
<p>I use an extended class of BarChart to add vertical lines and text on top of bars. This works fine but I want to display a small text at the top right of the horizontal line.</p>

<p>I tried this without success:</p>

<pre><code>public void addHorizontalValueMarker(Data&lt;X, Y&gt; marker) {
    Objects.requireNonNull(marker, "the marker must not be null");
    if (horizontalMarkers.contains(marker)) return;
    Line line = new Line();
    line.setStroke(Color.RED);        
    marker.setNode(line);
    getPlotChildren().add(line);

    // Adding a label
    Node text = new Text("average");
    nodeMap.put(marker.getNode(), text);
    getPlotChildren().add(text);

    horizontalMarkers.add(marker);
}

@Override
protected void layoutPlotChildren() {
    super.layoutPlotChildren();
    for (Node bar : nodeMap.keySet()) {
        Node text = nodeMap.get(bar);
        text.relocate(bar.getBoundsInParent().getMinX() + bar.getBoundsInParent().getWidth()/2 - text.prefWidth(-1) / 2, bar.getBoundsInParent().getMinY() - 30);
    }
    for (Data&lt;X, Y&gt; horizontalMarker : horizontalMarkers) {
        Line line = (Line) horizontalMarker.getNode();
        line.setStartX(0);
        line.setEndX(getBoundsInLocal().getWidth());
        line.setStartY(getYAxis().getDisplayPosition(horizontalMarker.getYValue()) + 0.5); // 0.5 for crispness
        line.setEndY(line.getStartY());
        line.toFront();
    }

}
</code></pre>

<p>What I'm doing wrong ?</p>