如何解决如何更改饼图的副标题 JAVAFX
我的代码几乎按照我想要的方式工作,唯一的问题是我的饼图副标题与饼图本身不匹配。我需要更改副标题中每件事的颜色,这是我的代码:
ObservableList<PieChart.Data> pieChartData =
FXCollections.observableArrayList(
//Creating the data shown on the pie graph
new PieChart.Data("Projects",20),//Needs to be set to red
new PieChart.Data("Quizzes",10),//Needs to be set to Blue
new PieChart.Data("Midterm",30),//Needs to be set to Green
new PieChart.Data("Final",40)); //Needs to be orange
final PieChart chart = new PieChart(pieChartData);
chart.setTitle("Grading");
//Displaying the scene
((Group) scene.getRoot()).getChildren().add(chart);
stage.setScene(scene);
stage.show();
applyCustomColors(
pieChartData,"Red","Blue","Green","Orange");
}
private void applyCustomColors(ObservableList<PieChart.Data> pieChartData,String... colors) {
int i = 0;
//Making a for loop through all the sets of data created
for (PieChart.Data data: pieChartData) {
data.getNode().setStyle("-fx-pie-color: " + colors[i % colors.length] + ";");
i++;
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。