struts2与jfreechart整合

public class ChartAction extends ActionSupport {
private static final long serialVersionUID = 1L;
private JFreeChart chart;

public JFreeChart getChart() {
//ChartFactory.createPieChart3D(title, dataset, legend, tooltips, urls)
chart=ChartFactory.createPieChart3D("图书销量统计图", getDataSet(), true, false, false);
chart.setTitle(new TextTitle("图书销量统计图", new Font("黑体", Font.ITALIC, 22)));
LegendTitle legend=chart.getLegend(0);
legend.setItemFont(new Font("宋体", Font.BOLD, 14));
PiePlot plot=(PiePlot) chart.getPlot();
plot.setLabelFont(new Font("隶书", Font.BOLD, 18));
plot.setBackgroundAlpha(0.9f);
plot.setForegroundAlpha(0.50f);
return chart;
}

private DefaultPieDataset getDataSet() {
DefaultPieDataset dataset=new DefaultPieDataset();
dataset.setValue("spring2.0 宝典", 47000);
dataset.setValue("轻量级J2EE企业实战", 38000);
dataset.setValue("基于J2EE的Ajax宝典", 31000);
dataset.setValue("JavaScript权威指南", 29000);
dataset.setValue("Ajax in Action", 25000);
return dataset;
}
}

Struts.xml配置文件
<package name="jfreechart" extends="jfreechart-default">
<action name="bookChart" class="com.struts2.web.action.ChartAction">
          <result name="success" type="chart">
          <param name="width">800</param>
          <param name="height">600</param>
          </result>
          </action>
    </package>

猜你喜欢

转载自jackaney.iteye.com/blog/1041025