gpt4 book ai didi

java - 如何更改 Piechart3D 部分的颜色

转载 作者:行者123 更新时间:2023-12-01 15:27:05 27 4
gpt4 key购买 nike

如何更改 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;



}

但是每次编译时,所有部分都会变成绿色,感谢您的帮助

最佳答案

这符合您正在寻找的东西吗?

Custom Colours for Pie Charts in JFreeChart

关于java - 如何更改 Piechart3D 部分的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10032758/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com