0
我正在顯示代表學位的每個模塊的執行學生的餅圖。我有的代碼顯示: output如何在JavaFX餅圖中顯示值?
但是我想每個切片的值出現在它內部,我不想要任何花哨的mouselistener的東西只是爲了顯示切片中的數字。
我的代碼如下:
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);
}
}
這是建議somethi ng略有不同。 http://stackoverflow.com/questions/35479375/display-additional-values-in-pie-chart – Sedrick