1. 3个jar包

jcommon,jfreechart,strust2-jfreechart-plugin

2

 <?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="default2" namespace="/" extends="jfreechart-default,struts-default">
<action name="resultAction" class="com.goshop.action.ShowResultAction" >
<result name="success" type="chart">
<param name="width">400</param>
<param name="height">300</param>
</result>
</action>
</package>
</struts>

3.

 package com.goshop.action;

 import java.awt.Font;
import java.util.List; import javax.annotation.Resource; import org.jfree.chart.ChartFactory;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.CategoryAxis;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.category.DefaultCategoryDataset;
import org.springframework.stereotype.Controller; import com.goshop.domain.VoteOption;
import com.goshop.service.IVoteOptionService;
import com.opensymphony.xwork2.ActionSupport; @Controller
public class ShowResultAction extends ActionSupport { private int voteID;
private int channelID; public int getVoteID() {
return voteID;
} public void setVoteID(int voteID) {
this.voteID = voteID;
} public int getChannelID() {
return channelID;
} public void setChannelID(int channelID) {
this.channelID = channelID;
} @Resource
private IVoteOptionService optionService;
private JFreeChart chart; public void setChart(JFreeChart chart) {
this.chart = chart;
}
public JFreeChart getChart(){ List<VoteOption> voteOptionList = optionService
.selectVoteOptionsByVoteId(voteID);
DefaultCategoryDataset ds = new DefaultCategoryDataset();
for (VoteOption option : voteOptionList) {
ds.addValue(option.getTicketNum(), option.getVoteOptionName(), "");
}
JFreeChart chart = ChartFactory.createBarChart("球星投票结果", "投票选项", "投票数",
ds, PlotOrientation.VERTICAL, true, false, false);
CategoryPlot categoryplot = (CategoryPlot) chart.getPlot();
NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
CategoryAxis domainAxis = categoryplot.getDomainAxis(); /*------设置X轴坐标上的文字-----------*/
domainAxis.setLabelFont(new Font("sans-serif", Font.PLAIN, 11));
/*------设置X轴的标题文字------------*/
domainAxis.setLabelFont(new Font("宋体", Font.PLAIN, 12));
/*------设置Y轴坐标上的文字-----------*/
numberaxis.setTickLabelFont(new Font("sans-serif", Font.PLAIN, 12));
/*------设置Y轴的标题文字------------*/
numberaxis.setLabelFont(new Font("黑体", Font.PLAIN, 12)); /*------这句代码解决了底部汉字乱码的问题-----------*/
chart.getLegend().setItemFont(new Font("宋体", Font.PLAIN, 12));
/******* 这句代码解决了标题汉字乱码的问题 ********/
/******* 这句代码解决了标题汉字乱码的问题 ********/
chart.getTitle().setFont(new Font("宋体", Font.PLAIN, 12)); return chart;
} public String execute() throws Exception {
return "success";
}
}

JFreeChart与struts2整合实例的更多相关文章

  1. struts2整合JFreechart 饼图、折线图、柱形图

    struts2整合JFreechart 饼图.折线图.柱形图 上效果图: 当然可以将数据导出图片格式存储.具体下的链接里的文件有保存成图片的操作. 因为是strust2整合JFreechart,所以s ...

  2. struts2整合spring应用实例

    我们知道struts1与spring整合是靠org.springframework.web.struts.DelegatingActionProxy来实现的,以下通过具体一个用户登录实现来说明stru ...

  3. struts2整合spring的思路

    struts2整合spring有有两种策略: >sping容器负责管理控制器Action,并利用依赖注入为控制器注入业务逻辑组件. >利用spring的自动装配,Action将自动会从Sp ...

  4. J2EE进阶(六)SSH框架工作流程项目整合实例讲解

    J2EE进阶(六)SSH框架工作流程项目整合实例讲解 请求流程 经过实际项目的进行,结合三大框架各自的运行机理可分析得出SSH整合框架的大致工作流程. 首先查看一下客户端的请求信息: 对于一个Web项 ...

  5. SSM框架快速整合实例——学生查询

    一.快速准备 SSM 框架即 Spring 框架.SpringMVC 框架.MyBatis 框架,关于这几个框架的基础和入门程序,我前面已经写过几篇文章作为基础和入门介绍了.这里再简单的介绍一下: 1 ...

  6. Spring4笔记12--SSH整合3--Spring与Struts2整合

    SSH 框架整合技术: 3. Spring与Struts2整合(对比SpringWeb): Spring 与 Struts2 整合的目的有两个: (1)在 Struts2 的 Action 中,即 V ...

  7. Spring Struts2 整合

    Spring整合Struts2 整合什么?——用IoC容器管理Struts2的Action如何整合?第一步:配置Struts21.加入Struts2的jar包.2.配置web.xml文件.3.加入St ...

  8. 【转】pringMVC+Hibernate+Spring 简单的一个整合实例

    ref:http://langgufu.iteye.com/blog/2088355 SpringMVC又一个漂亮的web框架,他与Struts2并驾齐驱,Struts出世早而占据了一定优势,我在博客 ...

  9. Spring与Struts2整合VS Spring与Spring MVC整合

    Spring与Struts2整合,struts.xml在src目录下 1.在web.xml配置监听器 web.xml <!-- 配置Spring的用于初始化ApplicationContext的 ...

随机推荐

  1. React Native 之 createBottomTabNavigator,createMaterialTopTabNavigator

    icon第三方库 yarn add react-native-vector-icons react-native link react-native-vector-icons 在上次的代码中添加: A ...

  2. MySQL把多条数据给汇总成一条数据

    用到的是这个函数: group_concat() select group_buying_id, group_concat(app_user_ids) from org_user_group grou ...

  3. 使用visual studio配置和运行《opengl圣经》的第一个案例

    对vc++新手来说,想把opengl圣经里的教学案例运行起来还真不是一件容易的事情,而且并没有完整的操作流程教学,这里就总结一下吧: 先安装cmake,用于生成vs的工程文件,安装过程中选中“将目录添 ...

  4. RabbitMQ绑定、队列、消息、虚拟主机详解(五)

    Binding:绑定,Exchange和Exchange.Queue之间的连接关系 Binding中可以包含RoutingKey或者参数 Queue:消息队列,实际存储消息数据 Durability: ...

  5. andriod工程项目总结

    1,胡萝卜农场项目 (1)图片缓存项目 (2)android开源框架的尝试 2,智能厨房项目 (1)将所有网络请求防止到一个service中的思路 (2)左右导航的实现 (3)fragment的使用 ...

  6. lambda匿名函数和内置函数

    对于简单的函数,也存在一种简便的表示方式,即:lambda表达式 定义函数(普通方式) def func(arg):     return arg + 1      执行函数 result = fun ...

  7. Java的参数传递是值传递?

    引用传递和值传递的区别.(不先说定义的都是在耍流氓!) 按值调用(call by value) : 在参数传递过程中,形参和实参占用了两个完全不同的内存空间.形参所存储的内容是实参存储内容的一份拷贝. ...

  8. P3373线段树2

    #include<bits/stdc++.h> using namespace std; typedef long long ll; ; ll sum[N<<],lazy1[N ...

  9. AtomicInteger 源码分析

    AtomicInteger AtomicInteger 能解决什么问题?什么时候使用 AtomicInteger? 支持原子更新的 int 值. 如何使用 AtomicInteger? 1)需要被多线 ...

  10. 爱好-超级IP:超级IP

    ylbtech-爱好-超级IP:超级IP  IP,是Intellectual Property的缩写,字面粗译为“知识产权”,特指具有长期生命力和商业价值的跨媒介内容运营.一个具有可开发价值的真正的I ...