struts2使用插件(jfreechart图表插件)
2013-10-11 22:55
453 查看
1.导入jar包:[jcommon-1.0.20.jar],[jfreechart-1.0.16.jar],[struts2-jfreechart-plugin-2.3.15.1.jar](struts2整合第三方插件的jar包,这里针对jfreechart,其他的去struts2下载的lib文件夹里找plugin结尾的jar包)
2.使用第三方插件的时候,在它们的jar包中肯定会提供一个struts-plugin.xml文件(这里再回顾下struts2加载配置文件的顺序,struts-default.xml--->struts-plugin.xml--->struts.xml),我们只要继承这个文件里他们定义的包,如果它有自定义的结果集,则使用它的结果集,写上他定义的参数即可。
struts2-jfreechart-plugin-2.3.15.1.jar中的struts-plugin.xml
例子:
struts.xml
Action
显示的页面
2.使用第三方插件的时候,在它们的jar包中肯定会提供一个struts-plugin.xml文件(这里再回顾下struts2加载配置文件的顺序,struts-default.xml--->struts-plugin.xml--->struts.xml),我们只要继承这个文件里他们定义的包,如果它有自定义的结果集,则使用它的结果集,写上他定义的参数即可。
struts2-jfreechart-plugin-2.3.15.1.jar中的struts-plugin.xml
<?xml version="1.0" encoding="UTF-8" ?> <!-- /* * $Id: struts-plugin.xml 1221225 2011-12-20 12:22:28Z jogep $ * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ --> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN" "http://struts.apache.org/dtds/struts-2.3.dtd"> <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>
例子:
struts.xml
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN" "http://struts.apache.org/dtds/struts-2.3.dtd"> <struts> <!-- 自动加载 --> <constant name="struts.devMode" value="true" /> <!-- 使用简单主题 --> <constant name="struts.ui.theme" value="simple"/> <!-- 继承上面那个struts-plugin.xml文件定义的包 --> <package name="myChart" extends="jfreechart-default"> <action name="myChart" class="com.xxc.action.GetChartAction"> <result type="chart"><!-- 开始我还以为这里这样写,那么返回success的时候就没法跳转到一个页面了,其实大可不必,只要在jsp里img标签的src属性写这个action路径就可以显示了 --> <param name="height">450</param> <param name="width">700</param> </result> </action> </package> </struts>
Action
public class GetChartAction extends ActionSupport implements Serializable{ private JFreeChart chart; public String execute() throws Exception { ValueAxis xAxis = new NumberAxis("年度"); ValueAxis yAxis = new NumberAxis("产值"); XYSeries xySeries = new XYSeries("绿豆"); xySeries.add(0,300); xySeries.add(1,200); xySeries.add(2,400); xySeries.add(3,500); xySeries.add(4,600); xySeries.add(5,500); xySeries.add(6,800); xySeries.add(7,1000); xySeries.add(8,1100); XYSeriesCollection xyDataset = new XYSeriesCollection(xySeries); XYPlot xyPlot = new XYPlot(xyDataset,xAxis,yAxis,new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES_AND_LINES)); chart = new JFreeChart(xyPlot); return SUCCESS; } public JFreeChart getChart() { return chart; } public void setChart(JFreeChart chart) { this.chart = chart; } }
显示的页面
<body> <s:url action="myChart" var="url"></s:url> <img alt="图表" src="<s:property value="#url"/>"> </body>
相关文章推荐
- struts2使用插件建立图表
- 使用JFreeChart整合Struts2开发图表
- 问题:MSChart.exe;结果:微软图表控件MsChart使用方法及各种插件下载地址
- 使用JFreeChart生成热点图表
- 在Struts2中使用SiteMesh插件
- 使用JFreeChart生成各种样式的图表
- 在Struts2中使用SiteMesh插件
- 使用自定义色系美化JfreeChart图表
- Struts2-Json插件的使用
- echarts图表插件的使用
- JFreeChart使用及乱码解决及整合struts2
- JQuery图表插件之 Highcharts使用指南
- Struts2中使用JfreeChart
- Struts2 注解零配置方法(convention插件使用)
- Struts2返回Json数据(使用Struts2插件)
- pChart图表插件使用
- Highcharts图表插件的使用说明
- 百度Echarts图表JS插件的使用
- Web图表开发工具JFreeChart与ChartDirector使用评测
- JFreeChart图表工具的使用(条形图、饼状图)