<!-- 报表消息 -->
<action name="formInfo_*" class="formInfoAction" method="{1}">
<result name="show" type="chart">
<param name="width">600</param>
<param name="height">400</param>
</result>
</action>
</package>
public String show() throws Exception{
// 调用方法
this.chart = JfreeChart.createChart();
return "show";
}
public JFreeChart getChart() {
return chart;
}
public void setChart(JFreeChart chart) {
this.chart = chart;
}
public class JfreeChart {
public static JFreeChart createChart() throws IOException {
// 数据集
DefaultPieDataset dpd = new DefaultPieDataset();
dpd.setValue("管理人员", 25);
dpd.setValue("市场人员", 25);
dpd.setValue("开发人员", 45);
dpd.setValue("其它人员", 10);
// 创建PieChart对象
JFreeChart chart = ChartFactory.createPieChart3D("某公司人员组织结构图", dpd,
true, true, false);
utils.setFont(chart);
return chart;
}
}
/**
* 设置字体
*
* @author zyong
*
*/
class utils {
public static void setFont(JFreeChart chart) {
Font font = new Font("宋体", Font.ITALIC, 12);
PiePlot plot = (PiePlot) chart.getPlot();
chart.getTitle().setFont(font);
plot.setLabelFont(font);
chart.getLegend().setItemFont(font);
}
}