Ireport交叉报表

1、构造数据源:


Ireport交叉报表_第1张图片

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交叉报表_第2张图片

3、创建交叉报表

row:


Ireport交叉报表_第3张图片

column:


Ireport交叉报表_第4张图片

value:


Ireport交叉报表_第5张图片

 

交叉报表创建成功。

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

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

详细设置如图:


Ireport交叉报表_第6张图片

效果如图:


Ireport交叉报表_第7张图片

最后交叉报表如图:


Ireport交叉报表_第8张图片
 

结果:


Ireport交叉报表_第9张图片

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

 

你可能感兴趣的:(IREPORT)