`
miaoge
  • 浏览: 107604 次
  • 性别: Icon_minigender_1
  • 来自: 嘉兴
社区版块
存档分类

【HRMS】JfreeChar创建数据统计图表、柱状图、饼状图···

阅读更多

JfreeChar创建人力资源管理系统数据统计图表

  导入下面的包

 

import java.io.FileOutputStream;
import java.io.IOException;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.category.DefaultCategoryDataset;

import com.opensymphony.xwork2.ActionSupport;
import com.wepull.hrms.biz.ChannelBiz;
import com.wepull.hrms.biz.DataCountBiz;
import com.wepull.hrms.dto.ChannelDto;
import com.wepull.hrms.dto.ChannelTypeDto;

/**
 * 数据统计模块action层
 * @author $KangMiao$
 */
public class DataCountAction extends ActionSupport{
	
	private DataCountBiz dataCountBiz = null;
	private ChannelBiz channelBiz = null;

	public void setDataCountBiz(DataCountBiz dataCountBiz) {
		this.dataCountBiz = dataCountBiz;
	}
	
	public void setChannelBiz(ChannelBiz channelBiz) {
		this.channelBiz = channelBiz;
	}
	
	/*******************************************************/
	private List<ChannelDto> channelList = new ArrayList<ChannelDto>();
	public List<ChannelTypeDto> typeList = new ArrayList<ChannelTypeDto>();
	private ChannelDto channelDto = new ChannelDto();
	
	/**统计某渠道 某种状态的简历数*/
	public String channelCount() throws IOException{
		typeList = channelBiz.findChannelType();
		List<ChannelDto> list = channelBiz.findChannel();
		int resumeCount=0,num1=0,num2=0,num3=0,num4=0,num5=0;
		if(channelList.size()!=0) channelList.clear();
		for ( ChannelDto dto: list) {
			resumeCount = dataCountBiz.countChannelResume(dto.getId());  //某渠道简历总数
			num1 = dataCountBiz.countResumeView(dto.getId(), 2);    //基本合格数
			num2 = dataCountBiz.countResumeView(dto.getId(), 3);    //专员面试合格数
			num3 = dataCountBiz.countResumeView(dto.getId(), 4);    //需求负责任面试合格数
			num4 = dataCountBiz.countResumeView(dto.getId(), 5);    //客户面试合格数
			num5 = dataCountBiz.countResumeView(dto.getId(), 6);    //实际到岗人数
			int[] count = new int[6];
			count[0] = resumeCount;
			count[1] = num1;
			count[2] = num2;
			count[3] = num3;
			count[4] = num4;
			count[5] = num5;
			dto.setCount(count);
			channelList.add(dto);
		}
		barChar();
		return SUCCESS;
	}
	/**生成渠道类型简历数据统计柱状图*/ 
	public void barChar() throws IOException{
		CategoryDataset dataset = getDataSet();
		JFreeChart chart = ChartFactory.createBarChart3D(
							"渠道类型简历数据统计图", // 图表标题
							"渠道类型", // 目录轴的显示标签
							"简历数量", // 数值轴的显示标签
							dataset, // 数据集
							PlotOrientation.VERTICAL, // 图表方向:水平、垂直
							true, 	// 是否显示图例(对于简单的柱状图必须是false)
							false, 	// 是否生成工具
							false 	// 是否生成URL链接
							);
							
		FileOutputStream fos_jpg = null;
		try {
			String projectRealPath= ServletActionContext.getServletContext().getRealPath("/");   //获得工程路径
			String imagePath = projectRealPath+"images/dataCount.jpg";
			System.out.println("图片路径3:-----------------------"+imagePath);
			fos_jpg = new FileOutputStream(imagePath);
			ChartUtilities.writeChartAsJPEG(fos_jpg,1,chart,900,400,null);
		} finally {
			try {
				fos_jpg.close();
			} catch (Exception e) {}
		}
	}
	
	/**统计渠道类别的简历数据*/
	public CategoryDataset getDataSet(){
		String[] typeName = {"合作伙伴","培训公司","招聘网","猎头公司","高等院校","中介公司","其他"};
		String[] dataName = {"简历总数","基本合格","专员面试合格","需求面试合格","客户面试合格","实际到岗人数"};
		int[] type1 = {0,0,0,0,0,0};   //合作伙伴类型
		int[] type2 = {0,0,0,0,0,0};   //培训公司类型
		int[] type3 = {0,0,0,0,0,0};   //招聘网类型
		int[] type4 = {0,0,0,0,0,0};   //猎头公司类型
		int[] type5 = {0,0,0,0,0,0};   //高等院校类型
		int[] type6 = {0,0,0,0,0,0};   //中介公司类型
		int[] type7 = {0,0,0,0,0,0};   //其他类型
		for (ChannelDto dto : channelList) {
			if (dto.getChannelTypeId() != null) {
				// 获得合作伙伴类型的数据
				if (dto.getChannelTypeId() == 3) {
					type1 = getData(type1, dto);
				}
				// 获得培训公司类型的数据
				else if (dto.getChannelTypeId() == 4) {
					type2 = getData(type2, dto);
				}
				// 获得招聘网类型的数据
				else if (dto.getChannelTypeId() == 22) {
					type3 = getData(type3, dto);
				}
				// 获得中介公司类型的数据
				else if (dto.getChannelTypeId() == 39) {
					type4 = getData(type4, dto);
				}
				// 获得猎头公司类型的数据
				else if (dto.getChannelTypeId() == 23) {
					type5 = getData(type5, dto);
				}
				// 获得高等院校类型的数据
				else if (dto.getChannelTypeId() == 37) {
					type6 = getData(type6, dto);
				}
				// 获得其他类型的数据
				else if (dto.getChannelTypeId() == 41) {
					type7 = getData(type7, dto);
				}
			}
		}
		//生成柱状图
		DefaultCategoryDataset dataset = new DefaultCategoryDataset();
		dataset = setData(dataset,type1,typeName[0],dataName);
		dataset = setData(dataset,type2,typeName[1],dataName);
		dataset = setData(dataset,type3,typeName[2],dataName);
		dataset = setData(dataset,type4,typeName[3],dataName);
		dataset = setData(dataset,type5,typeName[4],dataName);
		dataset = setData(dataset,type6,typeName[5],dataName);
		dataset = setData(dataset,type7,typeName[6],dataName);
		return dataset;
	}
	
	/**获得渠道类型的各种数据*/
	public int[] getData(int[] type,ChannelDto dto){
		type[0]=type[0]+dto.getCount()[0]; //获得简历总数
		type[1]=type[1]+dto.getCount()[1]; //获得基本合格数
		type[2]=type[2]+dto.getCount()[2]; //获得专员面试合格数
		type[3]=type[3]+dto.getCount()[3]; //获得需求负责任面试合格数
		type[4]=type[4]+dto.getCount()[4]; //获得客户面试合格数
		type[5]=type[5]+dto.getCount()[5]; //获得实际到岗人数
		return type;
	}
	
	public  DefaultCategoryDataset setData(DefaultCategoryDataset dataset,int[] type,
			String typeName,String[] dataName) {
		dataset.addValue(type[0], dataName[0], typeName);
		dataset.addValue(type[1], dataName[1], typeName);
		dataset.addValue(type[2], dataName[2], typeName);
		dataset.addValue(type[3], dataName[3], typeName);
		dataset.addValue(type[4], dataName[4], typeName);
		dataset.addValue(type[5], dataName[5], typeName);
		return dataset;
	}
	
	public static String fomat(float num){
		DecimalFormat df = new DecimalFormat("XXXX.0");
		System.out.println(df.format(num));
		return df.format(num);
	}
	
	/**查询某时间段渠道简历数*/
	public String findByTime() throws IOException{
		HttpServletRequest request = ServletActionContext.getRequest();
	      //判断 页面传的条件 
		String beginTime = request.getParameter("beginTime");
		String endTime = request.getParameter("endTime");
		typeList = channelBiz.findChannelType();
		List<ChannelDto> list = channelBiz.findChannel();
		int resumeCount=0,num1=0,num2=0,num3=0,num4=0,num5=0;
		if(channelList.size()!=0) channelList.clear();
		for ( ChannelDto dto: list) {
			resumeCount = dataCountBiz.countChannelTime(dto.getId(), beginTime, endTime); //某时间段渠道简历总数
			num1 = dataCountBiz.countByTime(dto.getId(), 2, beginTime, endTime);    //基本合格数
			num2 = dataCountBiz.countByTime(dto.getId(), 3, beginTime, endTime);    //专员面试合格数
			num3 = dataCountBiz.countByTime(dto.getId(), 4, beginTime, endTime);    //需求负责任面试合格数
			num4 = dataCountBiz.countByTime(dto.getId(), 5, beginTime, endTime);    //客户面试合格数
			num5 = dataCountBiz.countByTime(dto.getId(), 6, beginTime, endTime);    //实际到岗人数
			int[] count = new int[6];
			count[0] = resumeCount;
			count[1] = num1;
			count[2] = num2;
			count[3] = num3;
			count[4] = num4;
			count[5] = num5;
			dto.setCount(count);
			channelList.add(dto);
		}
		request.setAttribute("beginTime", beginTime);
		request.setAttribute("endTime", endTime);
		barChar();
		return "data";
	}
	
	
	
	/************************************/
	public ChannelDto getChannelDto() {
		return channelDto;
	}
	public void setChannelDto(ChannelDto channelDto) {
		this.channelDto = channelDto;
	}
	public List<ChannelDto> getChannelList() {
		return channelList;
	}
	public void setChannelList(List<ChannelDto> channelList) {
		this.channelList = channelList;
	}
}

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics