package com.zq.survey.web.action;
import java.awt.Font;
import java.text.DecimalFormat;
import java.util.List;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.labels.StandardPieSectionLabelGenerator;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PiePlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.data.general.DefaultPieDataset;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import com.zq.survey.base.BaseAction;
import com.zq.survey.domain.Page;
import com.zq.survey.domain.Question;
import com.zq.survey.domain.statistics.StatisticsQuestion;
import com.zq.survey.domain.statistics.StatisticsQuestionOption;
@Controller("statisticsAction")
@Scope("prototype")
public class StatisticsAction extends BaseAction<StatisticsQuestion> {
private static final long serialVersionUID = 4858307848656316447L;
//问题id
private Integer qid;
//调查id
private Integer sid;
//页面列表
private List<Page> pages;
// 图表类型
private int chartType;
private StatisticsQuestion sq;
/* 平面饼图 */
private static final int CHARTTYPE_PIE_2D = 0;
/* 立体饼图 */
private static final int CHARTTYPE_PIE_3D = 1;
/* 水平平面柱状图 */
private static final int CHARTTYPE_BAR_2D_H = 2;
/* 竖直平面柱状图 */
private static final int CHARTTYPE_BAR_2D_V = 3;
/* 水平立体柱状图 */
private static final int CHARTTYPE_BAR_3D_H = 4;
/* 竖直立体柱状图 */
private static final int CHARTTYPE_BAR_3D_V = 5;
/* 平面折线图 */
private static final int CHARTTYPE_LINE_2D = 6;
/* 立体折线图 */
private static final int CHARTTYPE_LINE_3D = 7;
private String[] colors = {
"#ff0000",
"#00ff00",
"#0000ff",
"#ffff00",
"#ff00ff",
"#000fff",
};
/**
*进入问题分析界面
*/
public String statisticsUI(){
pages=pageService.getPagesWithQuestionBySid(sid);
return "statisticsUI";
}
/**
* 统计矩形问题
*/
public String statisticsMatrix(){
sq=statisticsService.statistics(qid);
return ""+sq.getQuestion().getQuestionType();
}
/**
* 对问题进行报表
*/
public String chartOut(){
return "chartOut";
}
public JFreeChart getChart(){
//标题字体
Font titleFont=new Font("宋体", Font.BOLD, 25);
//普通字体
Font font=new Font("宋体", Font.PLAIN, 15);
//得到统计对象
StatisticsQuestion statisticsQuestion=statisticsService.statistics(qid);
//得到要统计的问题
Question question=statisticsQuestion.getQuestion();
//回答此问题的人数
long qcount=statisticsQuestion.getCount();
//报表的标题
String title=question.getTitle();
JFreeChart chart=null;
//饼图的结果集
DefaultPieDataset pieDataset=null;
//柱状图或线性图的结果集
DefaultCategoryDataset categoryDataset=null;
boolean legend=true;
boolean tooltips=true;
boolean urls=false;
String categoryAxisLabel="选项";
String valueAxisLabel="人数";
if(chartType<2){
pieDataset=new DefaultPieDataset();
for(StatisticsQuestionOption option:statisticsQuestion.getStatisticsQuestionOptions()){
pieDataset.setValue(option.getOptionLabel(), option.getCount());
}
}else{
categoryDataset=new DefaultCategoryDataset();
for(StatisticsQuestionOption option:statisticsQuestion.getStatisticsQuestionOptions()){
categoryDataset.addValue(option.getCount(), option.getOptionLabel(),"");
}
}
switch(chartType){
/* 平面饼图 */
case CHARTTYPE_PIE_2D:
chart=ChartFactory.createPieChart(title, pieDataset, legend, tooltips, urls);
break;
/* 立体饼图 */
case CHARTTYPE_PIE_3D:
chart=ChartFactory.createPieChart3D(title, pieDataset, legend, tooltips, urls);
break;
/* 水平平面柱状图 */
case CHARTTYPE_BAR_2D_H:
chart=ChartFactory.createBarChart(title, categoryAxisLabel, valueAxisLabel, categoryDataset, PlotOrientation.HORIZONTAL, legend, tooltips, urls);
break;
/* 竖直平面柱状图 */
case CHARTTYPE_BAR_2D_V:
chart=ChartFactory.createBarChart(title, categoryAxisLabel, valueAxisLabel, categoryDataset, PlotOrientation.VERTICAL, legend, tooltips, urls);
break;
/* 水平立体柱状图 */
case CHARTTYPE_BAR_3D_H:
chart=ChartFactory.createBarChart3D(title, categoryAxisLabel, valueAxisLabel, categoryDataset, PlotOrientation.HORIZONTAL, legend, tooltips, urls);
break;
/* 竖直立体柱状图 */
case CHARTTYPE_BAR_3D_V:
chart=ChartFactory.createBarChart3D(title, categoryAxisLabel, valueAxisLabel, categoryDataset, PlotOrientation.VERTICAL, legend, tooltips, urls);
break;
/* 平面折线图 */
case CHARTTYPE_LINE_2D:
chart = ChartFactory.createLineChart(title, categoryAxisLabel, valueAxisLabel, categoryDataset, PlotOrientation.HORIZONTAL, legend, tooltips, urls);
break;
/* 立体折线图 */
case CHARTTYPE_LINE_3D:
chart = ChartFactory.createLineChart3D(title, categoryAxisLabel, valueAxisLabel, categoryDataset, PlotOrientation.HORIZONTAL, legend, tooltips, urls);
break;
}
//设置标题字体
chart.getTitle().setFont(titleFont);
//设置提示条字体
chart.getLegend().setItemFont(font);
//如果是饼图效果
if(chart.getPlot() instanceof PiePlot){
PiePlot pieplot = (PiePlot) chart.getPlot();
pieplot.setLabelFont(font);
pieplot.setForegroundAlpha(0.7f);
pieplot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0}(回答人数:{1} 总人数:{3} 百分比:{2})"));
pieplot.setNoDataMessage("没有数据!");
}
//不是饼图,则是条形图或线性图
else{
CategoryPlot plot=chart.getCategoryPlot();
plot.getRangeAxis().setLabelFont(font);
plot.getRangeAxis().setTickLabelFont(font);
plot.getDomainAxis().setLabelFont(font);
plot.getDomainAxis().setTickLabelFont(font);
plot.setNoDataMessage("没有数据!");
}
return chart;
}
public String getScale(int rowIndex,int colIndex){
long ocount=0;
long qcount=sq.getCount();
float baifenbi=0f;
for(StatisticsQuestionOption sqo:sq.getStatisticsQuestionOptions()){
if(sqo.getMatrixRowIndex()==rowIndex&&sqo.getMatrixColIndex()==colIndex){
ocount=sqo.getCount();
break;
}
}
if(qcount!=0){
baifenbi=(float)ocount/qcount*100;
}
DecimalFormat df=new DecimalFormat("0.00");
String baifenbiStr=df.format(baifenbi);
return ocount+"("+baifenbiStr+"%)";
}
public String getScale(int rindex , int cindex,int oindex){
long ocount=0;
long qcount=sq.getCount();
float baifenbi=0f;
for(StatisticsQuestionOption sqo:sq.getStatisticsQuestionOptions()){
if(sqo.getMatrixRowIndex()==rindex&&sqo.getMatrixColIndex()==cindex&&sqo.getMatrixSelectIndex()==oindex){
ocount=sqo.getCount();
break;
}
}
if(qcount!=0){
baifenbi=(float)ocount/qcount*100;
}
DecimalFormat df=new DecimalFormat("0.00");
String baifenbiStr=df.format(baifenbi);
return ocount+"("+baifenbiStr+"%)";
}
public int getPercent(int rindex , int cindex,int oindex){
long ocount=0;
long qcount=sq.getCount();
float baifenbi=0f;
for(StatisticsQuestionOption sqo:sq.getStatisticsQuestionOptions()){
if(sqo.getMatrixRowIndex()==rindex&&sqo.getMatrixColIndex()==cindex&&sqo.getMatrixSelectIndex()==oindex){
ocount=sqo.getCount();
break;
}
}
if(qcount!=0){
baifenbi=(float)ocount/qcount*100;
}
return (int) baifenbi;
}
public Integer getQid() {
return qid;
}
public void setQid(Integer qid) {
this.qid = qid;
}
public Integer getSid() {
return sid;
}
public void setSid(Integer sid) {
this.sid = sid;
}
public List<Page>
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
基于android的问卷调查 (299个子文件)
StatisticsAction.class 9KB
EngageAction.class 9KB
BaseDaoImpl.class 7KB
PageServiceImpl.class 7KB
Install.class 5KB
AnchorTag.class 5KB
SurveyServiceImpl.class 4KB
PageAction.class 4KB
User.class 4KB
StatisticsServiceImpl.class 4KB
Question.class 4KB
SurveyAction.class 4KB
RoleAction.class 4KB
TestService.class 4KB
Survey.class 4KB
RightServiceImpl.class 4KB
RoleServiceImpl.class 4KB
QuestionServiceImpl.class 3KB
UserAction.class 3KB
UserServiceImpl.class 3KB
AnswerServiceImpl.class 3KB
BaseAction.class 3KB
Right.class 3KB
IniRightListener.class 3KB
Logger.class 3KB
LogServiceImpl.class 3KB
PageModel.class 2KB
QuestionAction.class 2KB
Page.class 2KB
StatisticsQuestionOption.class 2KB
RightInterceptor.class 2KB
DataUtil.class 2KB
Answer.class 2KB
StringUtil.class 2KB
Role.class 2KB
Log.class 2KB
LoginAction.class 2KB
LogAction.class 2KB
AjaxUtil.class 2KB
StatisticsQuestion.class 1KB
GenerateLogsTableTask.class 1KB
HomeAction.class 1KB
test.class 1KB
App.class 1KB
PageService.class 1KB
BaseDao.class 1KB
TestCommon.class 1KB
SurveyService.class 1007B
LogUtil.class 942B
RoleService.class 897B
ValidateUtil.class 742B
RightService.class 704B
QuestionService.class 687B
UserService.class 653B
LogService.class 519B
AnswerService.class 468B
TestGeneric.class 392B
StatisticsService.class 352B
.classpath 617B
org.eclipse.wst.common.component 608B
org.eclipse.wst.jsdt.ui.superType.container 49B
jquery-ui.css 32KB
jquery.treeview.css 3KB
common.css 841B
head.css 727B
sojump_logo.gif 7KB
freepub_logo.gif 5KB
headerbg.gif 2KB
treeview-default-line.gif 2KB
treeview-red-line.gif 2KB
treeview-gray-line.gif 2KB
treeview-black-line.gif 2KB
treeview-famfamfam.gif 1KB
treeview-red.gif 1KB
treeview-gray.gif 1KB
treeview-default.gif 1KB
treeview-black.gif 1KB
tab_17.gif 924B
plus.gif 841B
minus.gif 837B
treeview-famfamfam-line.gif 807B
tab_20.gif 770B
tab_07.gif 752B
back.gif 749B
next.gif 745B
last.gif 741B
go.gif 736B
first.gif 736B
tab_18.gif 715B
tab_03.gif 699B
tb.gif 585B
tab_19.gif 420B
tab_05.gif 375B
11.gif 341B
33.gif 337B
bg.gif 273B
22.gif 215B
edt.gif 197B
del.gif 145B
tab_15.gif 112B
共 299 条
- 1
- 2
- 3
虫兽
- 粉丝: 1
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
前往页