我想在折线图顶部显示值。我已经看到这个答案非常有帮助,但它改变了折线图节点。我想要的是相同的想法,但不是在节点上显示值,而是在它们附近(可能在它们的正上方),例如:
53
O
/ \
/ \
/42 \ 21 21
O O------------O
Run Code Online (Sandbox Code Playgroud)
编辑:
我尝试在下面编写代码,但遗憾的是只出现了线条,没有显示节点。
for (int index = 0; index < value.getData().size(); index++) {
XYChart.Data dataPoint = value.getData().get(index);
Node lineSymbol = dataPoint.getNode().lookup(".chart-line-symbol");
lineSymbol.setStyle("-fx-background-color: " + definedColor + " , white;");
Label label = new Label(value.getName());
label.toFront();
Pane nodeWithText = new Pane();
label.setStyle("-fx-font-size: 20; -fx-font-weight: bold;");
StackPane stackPane = new StackPane();
Group group = new Group(label);
group.getChildren().add(lineSymbol);
group.toFront();
group.setLayoutX(-10);
group.setLayoutY(-30);
StackPane.setAlignment(group, Pos.TOP_RIGHT);
StackPane.setMargin(group,new Insets(0,0,5,0));
nodeWithText.getChildren().add(group);
nodeWithText.getChildren().add(lineSymbol);
dataPoint.setNode(nodeWithText);
}
Run Code Online (Sandbox Code Playgroud)