gpt4 book ai didi

java - 为一个系列中的特定节点设置样式 - JavaFX

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:51:59 25 4
gpt4 key购买 nike

我正在编写一个测试程序,您必须达到 70% 以上才能通过测试。我已经设置了一个 LineChart 和一个系列,它将百分比值和日期作为坐标。我想为 >= 70% 绿色的节点着色,其余的节点着色为红色。这是一个代码片段:

for(final XYChart.Data<String, Number> data : series.getData()){
System.out.println(data.getXValue());
if(percent>=70){
data.getNode().setStyle("-fx-background-color: green;");
}else{
data.getNode().setStyle("-fx-background-color: red;");
}
data.getNode().addEventHandler(MouseEvent.MOUSE_MOVED, new EventHandler<MouseEvent>() {


@Override
public void handle(MouseEvent event) {
// TODO Auto-generated method stub
data.getNode().setCursor(Cursor.HAND);

Tooltip.install(data.getNode(), new Tooltip("Am: \n"+data.getXValue()+"\nZu: "+data.getYValue()+"%"));
}
});
}

问题是我无法为一个系列中的特定节点着色。我希望有人能够帮助我。

最佳答案

你必须从这样的事情开始。

//If you only have one series all you need is this first block of code
Set<Node> node = lineChart.lookupAll(".default-color0.chart-line-symbol.series0.");
node.forEach((element) -> {
//do somthing to each node in series0
System.out.println(element.toString());//don't know if this will work. If it does it will all you to see each node. At the very least the node address.
});

//If you have two series you need this. If you have more thant two series you need to copy this and change node2 to node3 everywhere in your copy.
Set<Node> node2 = lineChart.lookupAll(".default-color1.chart-line-symbol.series1.");
node2.forEach((element) -> {
//do somthing to each node in series1
System.out.println(element.toString());//don't know if this will work. If it does it will all you to see each node. At the very least the node address.
});

关于java - 为一个系列中的特定节点设置样式 - JavaFX,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40548320/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com