1 设置自己的系列,比如
private static final String FIRST = "<200米";
private static final String SECOND = "200-1000米";
private static final String THIRD = ">1000米";
2 加入数据集
private static PieDataset createDataset(int[] data) {
DefaultPieDataset defaultpiedataset = new DefaultPieDataset();
defaultpiedataset.setValue(FIRST, data[0]);
defaultpiedataset.setValue(SECOND, data[1]);
defaultpiedataset.setValue(THIRD, data[2]);
return defaultpiedataset;
}
3 修改颜色
private static JFreeChart createChart(String title, PieDataset piedataset, int[] data) {
JFreeChart jfreechart = ChartFactory.createPieChart3D(title, piedataset, true, true, false);
PiePlot3D pieplot3d = (PiePlot3D) jfreechart.getPlot();
pieplot3d.setStartAngle(290D);
pieplot3d.setDirection(Rotation.CLOCKWISE);
pieplot3d.setForegroundAlpha(0.8F);
pieplot3d.setNoDataMessage("没有数据");
pieplot3d.setLabelGenerator(new CustomLabelGenerator(data));
// 下面这几个是修改对应的颜色的
pieplot3d.setSectionPaint(FIRST, new Color(255, 0, 0));
pieplot3d.setSectionPaint(SECOND, new Color(255, 255, 0));
pieplot3d.setSectionPaint(THIRD, new Color(0, 255, 0));
pieplot3d.setDepthFactor(0.3f);
return jfreechart;
}