欢迎来到Doc100.Net免费学习资源知识分享平台!
您的位置:首页 > 程序异常 >

jasperreport 经过javabean datasoource实现chart的报表

更新时间: 2014-01-05 00:56:41 责任编辑: Author_N1

 

jasperreport 通过javabean datasoource实现chart的报表

       继上次report的demo后,还在继续做着report方面的research,今天主要是实现了通过javabean datasource填充chart图表,通过webservice下载pdf格式的报表。

       开始这一段快乐之旅吧,首先我在包下定义了两个类分别是Student和Mark,Student类下有三个属性,他们分别是

private String name;
private String number;
private List<Mark> mark;
Mark类下定义了两个属性

private String name;
private double mark;
另外写了一个函数去获取student的列表List,这将是填充JavaBean的数据源

public List<Student> getBeanData(){
		List<Student> listStudent = new ArrayList<Student>();
		Student student = new Student();
		student.setName("cheng");
		student.setNumber("01");
		
		List<Mark> listMark = new ArrayList<Mark>();
		listMark.add(new Mark("销售", 100));
		listMark.add(new Mark("IT", 139));
		listMark.add(new Mark("s", 110.6));
		listMark.add(new Mark("d", 120.4));
		listMark.add(new Mark("e", 120));
		
		student.setMark(listMark);
		listStudent.add(student);
		return listStudent;
	}
设计report chart报表


最后的任务是写webservice,打印出报表,贴主要的代码实现,有一些函数在上一篇文章中已经实现

public List<Student> getBeanData(){
		List<Student> listStudent = new ArrayList<Student>();
		Student student = new Student();
		student.setName("cheng");
		student.setNumber("01");
		
		List<Mark> listMark = new ArrayList<Mark>();
		listMark.add(new Mark("销售", 100));
		listMark.add(new Mark("IT", 139));
		listMark.add(new Mark("s", 110.6));
		listMark.add(new Mark("d", 120.4));
		listMark.add(new Mark("e", 120));
		
		student.setMark(listMark);
		listStudent.add(student);
		return listStudent;
	}
	
	//javabean
	@Path("download/chart")
	@Produces(MediaType.TEXT_PLAIN)
	@Transactional
	public String downloadReportByJavaBean(@Context HttpServletRequest req , @Context HttpServletResponse res) throws Exception{
		String designFilePath = req.getSession().getServletContext().getRealPath("/jasper") + 
				File.separator + "chartreport.jrxml";
		File designFile = new File(designFilePath);
		
		if(designFile.exists()){
			JRBeanCollectionDataSource dataSource = new JRBeanCollectionDataSource(getBeanData());
			JasperReport jasperReport = null;
			JasperDesign design = JRXmlLoader.load(designFile);
			jasperReport = JasperCompileManager.compileReport(design);
			
			JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport,null,dataSource);
			XLSReportProcess process = new XLSReportProcess();
			process.exportWebReport(ReportProcess.Type.pdf, res, jasperPrint , "chart.pdf");
			
		}
		return "success";
	}

最后实现的效果是通过webservice自动下载pdf文档,内容显示



上一篇:上一篇
下一篇:下一篇

 

随机推荐程序问答结果

 

 

如对文章有任何疑问请提交到问题反馈,或者您对内容不满意,请您反馈给我们DOC100.NET论坛发贴求解。
DOC100.NET资源网,机器学习分类整理更新日期::2014-01-05 00:56:41
如需转载,请注明文章出处和来源网址:http://www.doc100.net/bugs/t/1675/
本文WWW.DOC100.NET DOC100.NET版权所有。