【发布时间】:2016-08-14 16:48:02
【问题描述】:
我正在用 javafx 编写一个程序,我在其中使用气泡图、折线图、散点图和饼图来比较不同的公司和产品。我希望某家公司和属于它的所有产品在图表中出现时始终具有绿色。现在我正在使用 css 来设置图表的样式,并且我已经尝试了这些不同的替代方法来为特定系列设置颜色(在本例中是气泡图):
if(company.equals("MyCompany")) {
//alternative 1
Set<Node> nodes = series.getNode().lookupAll("chart-bubble");
for(Node node : nodes) {
node.getStyleClass().add("myCompany-chart-bubble");
}
//alternative 2
series.nodeProperty().get().setStyle("-fx-bubble-fill: #7fff00;");
//alternative 3
series.getData().get(0).getNode().getStyleClass().add("myCompany-chart-bubble");
//alternative 4
series.getNode().getStyleClass().add("myCompany-chart-bubble");
}
所有这些选择都会产生 NullPointerExceptions。这是为什么?有没有其他方法可以设置我想要的颜色?
谢谢!
【问题讨论】:
标签: javafx bubble-chart