Display javafx 2 string values ​​on hover

I used this example for my project and it works very well.

My question is: is it possible to compensate for the node hanging so that it does not overlap the data base point. The example centers the node hovering directly above the “normal” node. This somehow interferes with a chart with a lot of data points.

enter image description here

+4
source share
1 answer

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

  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;
    }
+6
source

Source: https://habr.com/ru/post/1524732/


All Articles