Jfreechart 生成不同数据源多个饼图(Multiple Pie Chart)

http://blog.163.com/ppy2790@126/blog/static/103242241201210130736274/

项目中要用JfreeChart实现不同数据源多个饼图展现每个班级的出勤率的显示。
 
Jfreechart 生成不同数据源多个饼图(Multiple Pie Chart) - ppy2790@126 - IT AIR
 
public String execute() throws Exception {
 
String checkInType[] = { "出勤", "病假", "事假", "其他" };
String clazzs[] = { "JSD1208班", "JSD1209班", "JSD1210班", "JSD1211班" };
String chartTitle = "各班级出勤情况";
 
// 创建数据集
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
 
// 构建数据
int checkInData;
for (int i = 0; i < checkInType.length; i++) {
for (int j = 0; j < clazzs.length; j++) {
checkInData = 1 + (int) (Math.random() * 1000);
dataset.addValue(checkInData, checkInType[i], clazzs[j]);
}
}
 
// 获取JFreeChart对象
chart = ChartFactory.createMultiplePieChart(
 
chartTitle, // 图表标题
dataset, // 数据集
TableOrder.BY_COLUMN, // 指定被提取数据的顺序
false, // 是否包含图例
true, // 是否包含提示工具
false // 是否包含url
);
// 获取PiePlot对象
MultiplePiePlot multiPlot = (MultiplePiePlot) chart.getPlot();
JFreeChart obj = multiPlot.getPieChart();
PiePlot plot = (PiePlot) obj.getPlot();
 
  //设置标签格式
plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} = {1} ({2})", NumberFormat.getNumberInstance(),
                new DecimalFormat("0.00%")));
 
// 分离圆弧
for (int i = 0; i < clazzs.length; i++) {
plot.setExplodePercent(i, 0.03);
}
 
ChartRenderingInfo info = new ChartRenderingInfo(
new StandardEntityCollection());
 
return SUCCESS;
}
 
原文地址:https://www.cnblogs.com/jukan/p/6611481.html