[六]JFreeChart实践五之与Struts2整合
1.Action,返回Chart
package com.java1234.chart.bar;
import java.awt.Color;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.labels.ItemLabelAnchor;
import org.jfree.chart.labels.ItemLabelPosition;
import org.jfree.chart.labels.StandardCategoryItemLabelGenerator;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.renderer.category.BarRenderer3D;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.general.DatasetUtilities;
import org.jfree.ui.TextAnchor;
import com.opensymphony.xwork2.ActionSupport;
public class BarCharAction extends ActionSupport{
/**
*
*/
private static final long serialVersionUID = 1L;
private JFreeChart chart;
public JFreeChart getChart() {
return chart;
}
@Override
public String execute() throws Exception {
double [][]data=new double[][]{{1320,1110,1123,321},{720,210,1423,1321},{830,1310,123,521},{400,1110,623,321}};
String []rowKeys={"苹果","香蕉","橘子","梨子"};
String []columnKeys={"深圳","北京","上海","南京"};
CategoryDataset dataset=DatasetUtilities.createCategoryDataset(rowKeys,columnKeys ,data);
chart=ChartFactory.createBarChart3D("水果销售统计图", "水果", "销售", dataset,
PlotOrientation.VERTICAL, true, true, true);
CategoryPlot plot=chart.getCategoryPlot();
// 设置网格背景颜色
plot.setBackgroundPaint(Color.white);
// 设置网格竖线颜色
plot.setDomainGridlinePaint(Color.pink);
// 设置网格横线颜色
plot.setRangeGridlinePaint(Color.pink);
// 显示每个柱的数值,并修改该数值的字体属性
BarRenderer3D renderer=new BarRenderer3D();
renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
renderer.setBaseItemLabelsVisible(true);
renderer.setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_LEFT));
renderer.setItemLabelAnchorOffset(10D);
// 设置平行柱的之间距离
renderer.setItemMargin(0.4);
plot.setRenderer(renderer);
return SUCCESS;
}
}
2.配置返回的chart
<?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>
<package name="jfreechart" extends="jfreechart-default">
<action name="barChart" class="com.java1234.chart.bar.BarCharAction">
<result name="success" type="chart">
<param name="value">chart</param>
<param name="type">png</param>
<param name="width">700</param>
<param name="height">500</param>
</result>
</action>
</package>
</struts>
3.配置struts2拦截器
<filter>
<filter-name>StrutsPrepareAndExecuteFilter</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>StrutsPrepareAndExecuteFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
[六]JFreeChart实践五之与Struts2整合的更多相关文章
- struts2整合JFreechart 饼图、折线图、柱形图
struts2整合JFreechart 饼图.折线图.柱形图 上效果图: 当然可以将数据导出图片格式存储.具体下的链接里的文件有保存成图片的操作. 因为是strust2整合JFreechart,所以s ...
- struts2整合spring应用实例
我们知道struts1与spring整合是靠org.springframework.web.struts.DelegatingActionProxy来实现的,以下通过具体一个用户登录实现来说明stru ...
- spring struts2整合
把struts2的action交给spring管理 一.导入相应jar包 导入与spring有关的基本jar包,和与struts2有关的基本jar包 还需要导入 struts2-spring整合jar ...
- Spring与Struts2整合VS Spring与Spring MVC整合
Spring与Struts2整合,struts.xml在src目录下 1.在web.xml配置监听器 web.xml <!-- 配置Spring的用于初始化ApplicationContext的 ...
- struts2整合spring的思路
struts2整合spring有有两种策略: >sping容器负责管理控制器Action,并利用依赖注入为控制器注入业务逻辑组件. >利用spring的自动装配,Action将自动会从Sp ...
- struts2整合spring出现的Unable to instantiate Action异常
在struts2整合spring的时候,完全一步步按照官方文档上去做的,最后发现出现 Unable to instantiate Action,网上一搜发现很多人和我一样的问题,配置什么都没有错误,就 ...
- struts2整合json要注意的问题
昨天struts2整合json,一直出错: There is no Action mapped for namespace / and action name ... HTTP Status 404 ...
- 20145203盖泽双《网络对抗技术》实践五:MSF基础应用
20145203盖泽双<网络对抗技术>实践五:MSF基础应用 1.实践目标 掌握metasploit的基本应用方式,掌握常用的三种攻击方式的思路.下面是我自己做的时候用的四个套路. (1) ...
- Linux及安全实践五——字符集编码
Linux及安全实践五——字符集编码 一.ASCII码 在表中查找出英文字母LXQ相对应的十六进制数值为: 4c 58 51 在终端中输入命令:vim test1.txt 在vim页面输入命令:%!x ...
随机推荐
- android 界面布局 很好的一篇总结[转]
1.LinearLayout ( 线性布局 ) :(里面只可以有一个控件,并且不能设计这个控件的位置,控件会放到左上角) 线性布局分为水平线性和垂直线性二者的属性分别为:android:orienta ...
- [转].NET程序在windows操作系统上独立运行的技术要点
发现一个不错的网站,转载一篇文章方便查看 转自 http://www.linuxdot.net/bbsfile-3354 ===================================== ...
- c++ 联合体
联合体分配的内存大小是成员变量中最大变量的大小 联合体的成员变量共享内存 小段模式(X86就是) 低位数据存在低地址单元 大端模式 高位字节存在低地址单元
- POj 2186 Popular Cows[连通分量]
题目大意:给出N头牛,有M种关系u, v.代表u牛崇拜v牛.要求找出有多少头牛被所有牛崇拜着题目链接:http://poj.org/problem?id=2186解题思路:1>求出强连通分量,标 ...
- POJ 1404 I-Keyboard (DP)
http://poj.org/problem?id=1404 题意 :手机上的要发短信的话,“我”字需要先按一下9键,再按3下6键,所以,现在想要重新布局每个键上的字母数,让最后的那个值最小,也就是说 ...
- Visual Studio 创建代码注释默认模版方法
在日常的开发中我们经常需要为页面添加注释和版权等信息,这样我们就需要每次去拷贝粘贴同样的文字,为了减少这种重复性的工作,我们可以把这些信息保存在Visual Studio 2012类库模版文件里 1. ...
- 协议(porotocol)
fly.h: #import <Foundation/Foundation.h> @protocol Fly -(void) go; -(void) stop; @optional -(v ...
- 【Python】代码行数统计
两级目录,可扩展为N级. # Count the line of dir or file import os, fnmatch, fileinput def ChkFileType(lst): tmp ...
- 使用git批量删除分支
要删除本地,首先要考虑以下三点 列出所有本地分支 搜索目标分支如:所有含有‘dev’的分支 将搜索出的结果传给删除函数 所以我们可以得到: git br |grep 'dev' |xargs git ...
- 阿里巴巴SUI Mobile的使用
1.引入文件 <link rel="stylesheet" href="./css/sm.min.css"> <link rel=" ...