首在在Action类里面必须有
然后在配置文件下面
加入jfreechart,jcommon,struts2-jfreechart-plugin的JAR包
最后把struts2-jfreechart-plugin.jar里面的插件的配置改了
http://struts.apache.org/2.x/docs/jfreechart-plugin.html
public class ViewModerationChartAction extends ActionSupport {
private JFreeChart chart;
public String execute() throws Exception {
// chart creation logic...
XYSeries dataSeries = new XYSeries(new Integer(1)); //pass a key for this serie
for (int i = 0; i <= 100; i++) {
dataSeries.add(i, RandomUtils.nextInt());
}
XYSeriesCollection xyDataset = new XYSeriesCollection(dataSeries);
ValueAxis xAxis = new NumberAxis("Raw Marks");
ValueAxis yAxis = new NumberAxis("Moderated Marks");
// set my chart variable
chart =
new JFreeChart(
"Moderation Function",
JFreeChart.DEFAULT_TITLE_FONT,
new XYPlot(
xyDataset,
xAxis,
yAxis,
new StandardXYItemRenderer(StandardXYItemRenderer.LINES)),
false);
chart.setBackgroundPaint(java.awt.Color.white);
return super.SUCCESS;
}
//一定要提供这个方法,而且一字不错的提供
public JFreeChart getChart() {
return chart;
}
}
然后在配置文件下面
<action name="viewModerationChart" class="myapp.actions.ViewModerationChartAction">
<result name="success" type="chart">
<param name="width">400</param>
<param name="height">300</param>
</result>
</action>
加入jfreechart,jcommon,struts2-jfreechart-plugin的JAR包
最后把struts2-jfreechart-plugin.jar里面的插件的配置改了
<!--这样方便使用-->
<struts>
<package name="jfreechart-default" extends="struts-default"> <result-types>
<result-type name="chart" class="org.apache.struts2.dispatcher.ChartResult">
<param name="height">150</param>
<param name="width">200</param>
</result-type>
</result-types>
</package>
</struts>
http://struts.apache.org/2.x/docs/jfreechart-plugin.html