Ireport交织报表

Ireport交叉报表

1、构造数据源:


Ireport交织报表

package test;

import java.util.ArrayList;

public class CrossReportFactory {

	public static Collection getData(){		
		 List<Map<Object, Object>> subGuestName = new ArrayList<Map<Object, Object>>();
            
		 //第一行A1
			subGuestNameInit(subGuestName, "C1", "A1","group1", "data1");
			subGuestNameInit(subGuestName, "C2", "A1","group1", "data12");
			subGuestNameInit(subGuestName, "C3", "A1","group1", "data13");
		
		//第二行A2
			subGuestNameInit(subGuestName, "C1", "A2","group1", "data123");
			subGuestNameInit(subGuestName, "C2", "A2","group1", "data1234");
			subGuestNameInit(subGuestName, "C3", "A2","group1", "data12345");
			
		//第三行还是按C1、C2、C3分3列,但却又按row2分多行
			subGuestNameInit(subGuestName, "C1", "A3","g2","d1");	
			subGuestNameInit(subGuestName, "C2", "A3","g2", "d12");	
			subGuestNameInit(subGuestName, "C3", "A3","g2", "d123");
			
			subGuestNameInit(subGuestName, "C1", "A3","g3","d11");	
			subGuestNameInit(subGuestName, "C2", "A3","g3", "d22");	
			subGuestNameInit(subGuestName, "C3", "A3","g3", "d33");
			
			
         return subGuestName;  
	}
	
	 public static void subGuestNameInit(List<Map<Object, Object>> subGuestName,String column,String row,String row2,String value){
		    Map<Object, Object> guestMap = new HashMap<Object, Object>();
		    guestMap.put("deptid", row);
		    guestMap.put("deptid2", row2);   //第三行继续划分使用
		    guestMap.put("degree", column);
		    guestMap.put("empid", value);
		    subGuestName.add(guestMap);
	    }
}

 2、新建一个模版,右击模版名添加Dataset,选择Dataset为刚创建的Dataset。为Dataset添加fields


Ireport交织报表

3、创建交叉报表

row:


Ireport交织报表

column:


Ireport交织报表

value:


Ireport交织报表

 

交叉报表创建成功。

但此时数据源还不可以,还得这样设置:

右击Detail中的交叉报表,选择Dataset run为"use dataset...",设置Dataset值为$P{REPORT_DATA_SOURCE}即可使用数据源。

详细设置如图:


Ireport交织报表

效果如图:


Ireport交织报表

最后交叉报表如图:


Ireport交织报表
 

结果:


Ireport交织报表

真正使用时隐藏掉红色部分即可达到要求。

 

1 楼 colbybobo 2011-10-13  
你好,我看了你写的文章,想问你几个关于交叉报表的问题,麻烦你了!我的邮箱:colbybobo@gmail.com   
QQ:103596214
2 楼 uule 2011-10-14  
哥们,我也是刚用到交叉报表的。。。
3 楼 w156445045 2012-05-09  
请问下,value我写两个数据该怎么办呢~