饼图默认为八种备选颜色,我们可以根据自己软件的风格选择适当的颜色,引入自定义的CSS。
.default-color0.chart-pie { -fx-pie-color: #dd3a2e; }
.default-color1.chart-pie { -fx-pie-color: #ff9e2c; }
.default-color2.chart-pie { -fx-pie-color: #ffdd40; }
.default-color3.chart-pie { -fx-pie-color: #9abd57; }
.default-color4.chart-pie { -fx-pie-color: #2bc9f7; }
.default-color5.chart-pie { -fx-pie-color: #1cabbb; }
.default-color6.chart-pie { -fx-pie-color: #2b73f7; }
.default-color7.chart-pie { -fx-pie-color: #9760f1; }
效果如图
当颜色超出默认的八种时,第9个类型又会回到第一种颜色,以此类推
效果如图
特别注意:饼图呈现选择的颜色是按类型存入的顺序分配。
ObservableList<Data> datas = FXCollections.observableArrayList(
new PieChart.Data("A", 1), //
new PieChart.Data("B", 0), //
new PieChart.Data("C", 2), //
new PieChart.Data("D", 4), //
new PieChart.Data("E", 0), //
new PieChart.Data("F", 1), //
new PieChart.Data("G", 3), //
new PieChart.Data("H", 2)); //
chart.setData(datas);
效果如图