Displaying javafx 2 linechart values on hover

javafx-2, linechart

Solution

A simple solution is to set a custom translation to the displayed `Label`. The following code is extracted from the example.

  private Label createDataThresholdLabel(int priorValue, int value)
    {
        final Label label = new Label(value + "");
        label.setTranslateY(-25); //Move label 25 pixels up
        label.getStyleClass().addAll("default-color0", "chart-line-symbol", "chart-series-line");
        label.setStyle("-fx-font-size: 20; -fx-font-weight: bold;");

        if (priorValue == 0)
        {
            label.setTextFill(Color.DARKGRAY);
        }
        else if (value > priorValue)
        {
            label.setTextFill(Color.FORESTGREEN);
        }
        else
        {
            label.setTextFill(Color.FIREBRICK);
        }

        label.setMinSize(Label.USE_PREF_SIZE, Label.USE_PREF_SIZE);
        return label;
    }

Problem

I have been using this example for my project, and it works really nice. My question: Is it possible to offset the hovered node such that it does not overlay the underlying data point. The example centers the hovered node right over the "normal" node. It kind of gets in the way on a chart with a lot of data points.

Original source

Related problems