RonSiven
RonSiven

Reputation: 959

Displaying javafx 2 linechart values on hover

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.

enter image description here

Upvotes: 4

Views: 4222

Answers (1)

denhackl
denhackl

Reputation: 1115

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;
    }

Upvotes: 6

Related Questions