jfreechart在struts2 中使用配置步骤
配置步骤:
1.在struts.xml中添加:
<struts>
<package name="analysemessage" extends="granite" namespace="/analyseMessage">
<!-- 为jfreechart 添加result types -->
<result-types>
<result-type name="chart" class="org.apache.struts2.dispatcher.ChartResult"/>
</result-types>
这里的class 是在struts-jfreechart-plugin.jar 中;
2.程序中需要到入的包:
3.和其他action写法一样,要在数据困苦中查询数据,通过Service返回一个List对象;
写一个方法给图标赋值:
4.
写一个方法给图形赋值并定义下关属性:
CategoryDataset dataset = getDataSet2();
JFreeChart chart = ChartFactory.createBarChart3D(
"对比分析消息图", // 图表标题
"地市", // 目录轴的显示标签
"消息数量", // 数值轴的显示标签
dataset, // 数据集
PlotOrientation.VERTICAL, // 图表方向:水平、垂直
true, // 是否显示图例(对于简单的柱状图必须是false)
true, // 是否生成工具
false // 是否生成URL链接
);
return chart;
6.在action中写一个方法:
给chart 赋值:
chart = *****.createBarChart();
return SUCCESS;
7.在struts.xml配置文件中添加:
<action name="*******action" class="********" method="********">
<result name="success" type="chart" >
<param name="height">600</param>
<param name="width">800</param>
</result>
</action>
8.在jsp页面写一个Button 转到 7中的action即可!