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. PHP培训教程 PHP的运算符

    PHP中有丰富的运算符集,它们中大部分直接来自于C语言.按照不同功能区分,兄弟连PHP培训 运算符可以分为:算术运算符.字符串运算符.赋值运算符.位运算符.条件运算符,以及逻辑运算符等.当各种运算符在 ...

  2. C#删除文件夹的文件

    using System.IO; //判断文件是不是存在if(File.Exists(@"文件路径")){//如果存在则删除File.Delete(@"文件路径" ...

  3. HDU 4348 SPOJ 11470 To the moon

    Vjudge题面 Time limit 2000 ms Memory limit 65536 kB OS Windows Source 2012 Multi-University Training C ...

  4. Leetcode 3. Longest Substring Without Repeating Characters(string 用法 水题)

    3. Longest Substring Without Repeating Characters Medium Given a string, find the length of the long ...

  5. Windows Server 2003 IIS 使用 Excel.Application

    在Server2003服务器系统中,配置ASP调用CreateObject("Excel.Application")对象 1.先在服务器中安装Microsoft Excel 2.打 ...

  6. [CF1082G]Petya and Graph:最小割

    分析 发这篇博客的目的就是要让你们知道博主到底有多菜. 类似于[NOI2006]最大获利.(明明就是一模一样好吧!) 不知道怎么了,半秒就想到用网络流,却没想出怎么建图. 连这么简单的题都没做出来,我 ...

  7. Dancing Stars on Me

    Dancing Stars on Me Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Ot ...

  8. 使用xshell远程连接Linux

    Linux系统对于程序员来说并不陌生,对IT技术员来说是一个很好的开发平台,因此掌握Linux系统的操作对于一个程序员来说非常有用.而对于习惯使用windows的人来说直接在Linux系统下进行操作感 ...

  9. Android4.0 Camera架构初始化流程【转】

    本文转载自:http://blog.chinaunix.net/uid-2630593-id-3307176.html Android Camera 采用C/S架构,client 与server两个独 ...

  10. 用流的方式来操作hdfs上的文件

    import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import ...