如何更改 PieChart3D 中每个部分的颜色,我试过这样:
private Color[] COLORS = {Color.red,Color.yellow,Color.blue,Color.black,Color.green};
private PieDataset createSampleDataset() {
final DefaultPieDataset result = new DefaultPieDataset();
result.setValue("Java", new Double(43.2));
result.setValue("Visual Basic", new Double(10.0));
result.setValue("C/C++", new Double(17.5));
result.setValue("PHP", new Double(32.5));
result.setValue("Perl", new Double(1.0));
return result;
}
private JFreeChart createChart(PieDataset dataset) {
final JFreeChart chart = ChartFactory.createPieChart3D(
"Pie Chart 3D Demo 1", // chart title
dataset, // data
true, // include legend
true,
false
);
final PiePlot3D plot = (PiePlot3D) chart.getPlot();
plot.setStartAngle(290);
plot.setDirection(Rotation.CLOCKWISE);
for(int i=0;i<COLORS.length;i++){
plot.setSectionPaint(COLORS[i]);
}
plot.setForegroundAlpha(0.5f);
plot.setNoDataMessage("No data to display");
return chart;
}
但是每次我编译时,所有的部分都会有绿色,谢谢你的帮助