4

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

Community
  • 1
  • 1
RonSiven
  • 939
  • 2
  • 10
  • 23
  • Hello Ron. I'm searching for a way to draw horizontal/vertical lines on a chart, at exact points on the axis. It seems that your orange line on the chart picture you've posted suits my needs perfectly. Would you be kind enough to provide the source code for that? – Georgian Mar 07 '14 at 14:23
  • Hi @GGrec, That line is actually nothing more than another plotted series on the chart. I've actually done that with a trend line on another chart as well. Just calculate and add a new 2-point series. – RonSiven Mar 07 '14 at 15:35
  • Hi @RonSiven can you please tell me how are you able to show time at x-axis. actually I need to show time at x-axis from 00:00 to 24:00 in my project. – Junaid Jul 13 '17 at 12:38
  • The contents of the hover is just a Node. In this case, it's a VBox with 2 Text nodes inside. The first is the value of y with a meaningful label and some formatting, and the second is the formatted value of x. Please check out the example I refer to in the original post to see how to get values in the hover. – RonSiven Jul 19 '17 at 04:29

1 Answers1

6

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;
    }
denhackl
  • 1,085
  • 1
  • 8
  • 12