【发布时间】:2017-02-06 10:46:05
【问题描述】:
我正在显示一个饼图,代表学位的每个模块中表现不佳和表现不佳的学生。我的代码显示了这个: output
但是我希望每个切片的值都显示在其中,我不希望任何花哨的鼠标监听器只是为了显示切片中的数字。
我的代码如下:
public class PieChartSample extends Application { //TODO make constructor that takes hashmaps as arguments
static Map<String, Integer> studsabove = new HashMap<String, Integer>();
static Map<String, Integer> studsbelow = new HashMap<String, Integer>();
@Override
public void start(Stage primaryStage) throws Exception {
primaryStage.setTitle("My First JavaFX App");
ArrayList<PieChart> pielist = new ArrayList<PieChart>();
for(Entry<String, Integer> mod: studsabove.entrySet()){
for(Entry<String, Integer> mod2: studsbelow.entrySet()){
PieChart pieChart = new PieChart();
PieChart.Data above = new PieChart.Data(mod.getKey(), mod.getValue());
PieChart.Data below = new PieChart.Data(mod2.getKey(), mod2.getValue());
pieChart.getData().add(above);
pieChart.getData().add(below);
pielist.add(pieChart);
}
}
VBox vbox = new VBox();
for (PieChart pie: pielist){
pie.setLabelLineLength(10); //FIXME
pie.setLegendSide(Side.LEFT);
vbox.getChildren().add(pie);
}
Scene scene = new Scene(vbox, 400, 200); //TODO: Make pie charts appear horizontally rather than vertically
primaryStage.setScene(scene);
primaryStage.setHeight(900);
primaryStage.setWidth(400);
primaryStage.show();
}
public static void main(String[] args) { //TODO: need to figure out how to display the values in the slices of the pie charts
PieChartSample.studsabove.put("CE201", 23);
PieChartSample.studsbelow.put("CE201", 67);
PieChartSample.studsabove.put("CE222", 20);
PieChartSample.studsbelow.put("CE222", 80);
PieChartSample.studsabove.put("CE233", 6);
PieChartSample.studsbelow.put("CE233", 94);
PieChartSample.studsabove.put("CE244", 56);
PieChartSample.studsbelow.put("CE244", 44);
Application.launch(args);
}
}
【问题讨论】:
标签: java javafx graph graphics pie-chart