<%
/*****************************************************************************
*	File name		: ErPrintReportBuilder.jsp
*	Purpose			: This page Handles Report Builder Report
*	Created by		: Gowtham
*	Version			: Reporter 6.2
********************************************************************************/
%>
<%@ include file="ErTracker.jsp"%>
<%@ page import="egurkha.reporter.*"%>
<%@ page import="com.eg.EgDiscInfoHelper"%>
<%@ page import="java.util.Date"%>
<%@ page import="java.util.*"%>
<%@ page import="java.util.regex.*"%>
<%@ page import="egurkha.TransactionBean"%>
<%@ page import="egurkha.EgDbAdapterUI"%>
<%@ page import="com.eg.EgDbAdapterTypeUI"%>
<%@ page import="com.eg.*"%>
<%@ page import="com.eg.EgDbInfo"%>
<%@ page import="com.eg.IniFile"%>
<%@ page import="com.eg.EgInstallInfo,com.eg.EgTopoInfo,com.eg.EgSpecsInfo"%>
<%@ page import="egurkha.EgCrawler"%>
<%@ page import="com.eg.EgTopoInfo"%>
<%@ page import="com.eg.EgDateInfo"%>
<%@ page import="java.text.Format.*"%>
<%@ page import="java.text.DateFormat.*"%>
<%@ page import="java.text.*"%>
<%@ page import="java.net.*" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%@ page import="com.eg.EgReportInfo"%>
<%@ page import="com.eg.EgMappingInfo"%>
<%@ page import="com.eg.EgTablesInfo"%>
<%@ page import="com.egurkha.util.DateUtil"%>
<%@ page import="com.egurkha.util.*"%>
<%@ page import="com.egurkha.util.DateTimeTokenizer"%>
<%@ page import="com.eg.EgTesterInfo"%>
<%@ page import="com.eg.EgTestInfo"%>
<%@ page import="com.eg.EgURLDecoder"%>
<%@ page import="com.eg.EgDbInfo"%>
<%@ page import="com.eg.EgConfigInfo"%>
<%@ page import="java.io.*"%>
<%@ page import="com.egurkha.util.StringUtils"%>
<%@ taglib prefix="egui" uri="../WEB-INF/eg-taglib.tld"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import = "com.egurkha.monitor.EgServiceMappingBean"%>
<%@ page import="com.egurkha.util.StringUtils"%>
<%@ page import = "net.sf.json.*" %>

<jsp:useBean id="esmb" scope="page" class="com.egurkha.monitor.EgServiceMappingBean" />
<%
	String qStrng =(String)ErUtils.prepareQueryString(request.getParameterMap());
	
	EgReportInfo reportInfo=new EgReportInfo("manager");
	ErUtils utils=new ErUtils();
	EgMappingInfo intlmap=new EgMappingInfo(thisuser.getLanguage());
	EgDbInfo dbInfo = new EgDbInfo("manager");
	ErReqData erd = new ErReqData(request);
	
	System.out.println("ErReportBuilder.jsp query string  "+request.getQueryString());
	JSONObject resultJson=null;
	if(request.getParameter("dataDrill") != null)
	{
		String dataDrill=(String)request.getParameter("dataDrill");
		if(dataDrill.equals("yes"))
			resultJson = (JSONObject) session.getAttribute("htdataDrillDown");
	}
	else
		resultJson = (JSONObject) session.getAttribute("htdata");
	System.out.println("===resultJson======>>>..>>>>>>>>"+resultJson);

	String widgetIdInfo = (String)request.getParameter("widgetIdInfo");
	String strShowBy = "";
	if(request.getParameter("timeline_showBy")!=null)
		strShowBy = request.getParameter("timeline_showBy");
	if(strShowBy == null || strShowBy.equalsIgnoreCase("null"))
	{
		if(request.getParameter("bar_showBy")!=null)
			strShowBy = request.getParameter("bar_showBy");
	}
	String reportBy=request.getParameter("infoBy");//..for load evaluator index report
	if(reportBy != null && (reportBy.equalsIgnoreCase("deliveryGroups") || reportBy.equalsIgnoreCase("machines")))
		strShowBy="componentWise";
	String printBy = (String)request.getParameter("printBy");
	String sessionCompName = (String)request.getParameter("compName");
	System.out.println("=====pritnBy=======>>>jsp>>"+printBy);
	System.out.println("===sessionCompName======>>>..>>>>>>>>"+sessionCompName);
	System.out.println("===widgetIdInfo======>>>..>>>>>>>>"+widgetIdInfo);
	System.out.println("===strShowBy======>>>..>>>>>>>>"+strShowBy);
	//System.out.println("=========pdfby=====jsp==>>>>>"+request.getParameter("pdfBy"));
		
	String fontStyleDbl = "";
	String fontStyleDblSingl = "";
	String pdfPrint = request.getParameter("pdfPrint");
	JSONObject selDetails=null;
	//String titleToDisplay=request.getParameter("er_RmDispName");
	String titleToDisplay=request.getParameter("titleDisp");
	if(titleToDisplay != null && titleToDisplay.indexOf("jsessionid") > -1)
		titleToDisplay=titleToDisplay.substring(0,titleToDisplay.indexOf(";"));
	String needNoMeasure=(String)resultJson.get("needNoMeasure");
	String firstColWordBreakPrint=(String)resultJson.get("firstColWordBreakPrint");
	if(resultJson.get("templateTitle") != null)
	{
		titleToDisplay=(String)resultJson.get("templateTitle");
	}
	if(resultJson.get("selectionDetails") != null)
	{
		selDetails=new JSONObject();
		selDetails=(JSONObject)resultJson.get("selectionDetails");
	}
	String tempDesc=(String)request.getParameter("tempDesc");
	System.out.println("ErPrintCustomReportBuilder ===tempDesc=.>>>>>>>>"+tempDesc);
	if(tempDesc==null)
	{
		tempDesc="";
	}
	String timefrom = request.getParameter("timefrom");
	String timeto = request.getParameter("timeto");
	String minfrom = request.getParameter("minfrom");
	String minto = request.getParameter("minto");
	String Strexcwe = request.getParameter("er_excwe");
	String fromdistributedPie=request.getParameter("fromdistributedPie");
	String dispStartDate = null;
	String dispEndDate = null;
	String start_date=erd.s_stdate;
	String end_date=erd.s_enddate;
	String graphIndex="";
	System.out.println("titleToDisplaytitleToDisplay  = "+titleToDisplay);
	String timePeriod="Time Period:From"+timefrom+":"+minfrom+"Hrs To "+timeto+":"+minto+"Hrs";
	System.out.println("====timePeriod==>>>"+timePeriod);

	if(start_date==null)
	{
		
		start_date=(String)request.getParameter("er_stdate");
	}
	if(end_date==null)
	{
		end_date=(String)request.getParameter("er_enddate");
	}
	String opt = request.getParameter("opt");
	String Days = reportInfo.getExcludeWeekend("RUM_REPOTRS");
	
	EgDateInfo egDate = new EgDateInfo();
	Calendar cal = Calendar.getInstance();
	Date local_date = new Date(egDate.egetUTCDate());	  
	cal.setTime(local_date);
	cal.setTimeZone(egDate.getRealTimeZone());
	String temp1 = (cal.get(cal.MONTH)+1) + "/" + cal.get(cal.DAY_OF_MONTH) + "/" +cal.get(cal.YEAR);
	String mgr_time = cal.get(cal.HOUR_OF_DAY)+":"+cal.get(cal.MINUTE)+":"+cal.get(cal.SECOND);
	String dispDate = DateUtil.changeDateFormat(temp1,"MM/dd/yyyy",strUserDateFormat);
	TimeZone tzne = egDate.getRealTimeZone();
	String tzName = tzne.getDisplayName(tzne.inDaylightTime(local_date), TimeZone.SHORT);
	EgTimeZoneConverter timeZoneConverter = new EgTimeZoneConverter(dispDate+" "+mgr_time,thisuser);
	String loginUserDateTime = (String)timeZoneConverter.getDate(false);
	Date loginUserDate = (Date)timeZoneConverter.getDate(true);
	TimeZone user_tz = (TimeZone)timeZoneConverter.getTimeZone();
	String st_hr=erd.s_sthr,end_hr=erd.s_endhr;
	String st_min=erd.s_startmin,end_min=erd.s_endmin;	
	if( loginUserDateTime != null && !loginUserDateTime.trim().equals(""))
	{
		dispDate = loginUserDateTime;
		tzName = user_tz.getDisplayName(user_tz.inDaylightTime(loginUserDate), TimeZone.SHORT);
	}
	if(st_hr==null||st_hr.trim().length()==0)
	{
	st_hr="00";
	}
	if(st_min==null||st_min.trim().length()==0)
	{
	st_min="00";
	}
	if(end_hr==null||end_hr.trim().length()==0)
	{
	end_hr="00";
	}
	if(end_min==null||end_min.trim().length()==0)
	{
	end_min="00";
	}
	if(start_date!=null && end_date!=null)
	{
		dispStartDate=start_date.trim()+" "+st_hr+":"+st_min;	
		dispEndDate=end_date.trim()+" "+end_hr+":"+end_min;	
	}
	String st_dateTime ="";
	String en_dateTime="";
	System.out.println("dispStartDate:::::::::::::   "+dispStartDate);
	System.out.println("dispEndDate:::::::::::::   "+dispEndDate);
	System.out.println("thisuser:::::::::::::   "+thisuser);
	EgTimeZoneConverter converterStart = new EgTimeZoneConverter(dispStartDate,thisuser);
	EgTimeZoneConverter converterEnd = new EgTimeZoneConverter(dispEndDate,thisuser);
	st_dateTime = converterStart.getDateTime();
	en_dateTime = converterEnd.getDateTime();

	System.out.println("====st_dateTime========>>>>>..>>"+st_dateTime);
	System.out.println("====en_dateTime========>>>>>..>>"+en_dateTime);
	System.out.println("=====chartinfo===="+request.getParameter("chartInfo"));
	String chartInfoString=request.getParameter("chartInfo");
	String chart_type=null;
	/*if(chartInfoString==null)
		chart_type="timeline";
	else*/
	if(chartInfoString!=null)
	{
		JSONObject chartInfoObj = (JSONObject) JSONSerializer.toJSON(chartInfoString);				
		chart_type=(String)chartInfoObj.get("chartType");
	}
	String scheduleMailFormat="";
	if(request.getParameter("scheduleMailFormat") != null)
		scheduleMailFormat=(String)request.getParameter("scheduleMailFormat");
	String dataPageNo=request.getParameter("dataPageNo");
	
	if(request.getParameter("option") != null || (scheduleMailFormat != null && scheduleMailFormat.equalsIgnoreCase("csv")))
	{
		String option ="";
	if(request.getParameter("option") != null)
	{
			option=request.getParameter("option").toString();			
		}
		if(scheduleMailFormat != null && scheduleMailFormat.equalsIgnoreCase("csv"))
			option="mainCsv";
		if(option.equals("csv"))
		{
			System.out.println("==========option=========>>>>>>"+option);
			//......
			JSONObject widgetObj=(JSONObject)resultJson.get(widgetIdInfo);
				System.out.println("widgetObjwidgetObjwidgetObj   "+widgetObj);
				//JSONArray timelineArray=(JSONArray)widgetObj.get("timeline");
				//if(chart_type==null||chart_type.length()==0)
				//{
					Iterator itr2 = widgetObj.entrySet().iterator();
					while(itr2.hasNext())
					{
						Map.Entry entry2= (Map.Entry)itr2.next();	
						String key=(String)entry2.getKey();
							
						if(key.equalsIgnoreCase("widgetHeader"))
						{
							//widgetHeader=key;
							continue;
						}
						else if(key.equalsIgnoreCase("widgetFooter"))
						{
							//widgetFooter=key;
							continue;
						}
						else if(key.equalsIgnoreCase("headerDescription"))
						{
							//headerDescription=key;
							continue;
						}
						else if(key.equalsIgnoreCase("widgetHeight"))
						{
							//headerDescription=key;
							continue;
						}
						else if(key.equalsIgnoreCase("adjustWidgetHeight"))
						{
							//headerDescription=key;
							continue;
						}
						else if(key.equalsIgnoreCase("widgetWidth"))
						{
							//headerDescription=key;
							continue;
						}
						else if(key.equalsIgnoreCase("widgetPosition"))
						{
							//headerDescription=key;
							continue;
						}
						else if(key.equalsIgnoreCase("widgetSize"))
						{
							//headerDescription=key;
							continue;
						}
						else if(key.equalsIgnoreCase("DigitalChartCount") || key.equalsIgnoreCase("lineCls"))
						{
							continue;
						}
						else
						{
							chart_type=key;
						}
					}
			//	}

				
					System.out.println("====check====chart_type==>>>>"+chart_type);
				
			//......
			graphIndex = (String)request.getParameter("graphIndex");
			if(chart_type!= null && !chart_type.equalsIgnoreCase("table")&&!chart_type.equalsIgnoreCase("topn"))
				resultJson=prepareResultJsonforGrid(chart_type,widgetIdInfo,resultJson,Integer.parseInt(graphIndex),strUserDateFormat,sessionCompName,thisuser);//..
		  
			System.out.println("===resultJson====csv..==>>>..>>>>>>>>"+resultJson);
			JSONObject widget=(JSONObject)resultJson.get("widget");
			
			JSONArray tableArray=null;
			tableArray=(JSONArray)widget.get("table");
			JSONObject dataObject=(JSONObject)tableArray.get(0);
			System.out.println("=========dataObject========dfd>>>>>"+dataObject);
		
			JSONArray gridCollection=null;
			if(sessionCompName!=null && !sessionCompName.equalsIgnoreCase("null") && sessionCompName.length()>0)
			{				
				gridCollection=(JSONArray)(((JSONObject)dataObject.get("gridCollection")).get(sessionCompName));
				
			}
			else
			{
				gridCollection=(JSONArray)dataObject.get("gridCollection");//..
			}
			JSONObject gridObject=(JSONObject)gridCollection.get(0);
			JSONArray columnArray=(JSONArray)gridObject.get("gridColums");
			JSONArray dataArray=(JSONArray)gridObject.get("gridData");
			String title="";
			if(gridObject.get("title") != null)
				title=gridObject.get("title").toString();
			LinkedList list=new LinkedList();
			list.add(title);
			
			Vector dateVector=new Vector();
			dateVector.add("\""+"Start Date : "+st_dateTime+" hrs\"");
			dateVector.add("\""+"End Date : "+en_dateTime+" hrs\"");		
			list.add(dateVector);
			
			Hashtable measureTable=new Hashtable();
			Hashtable submeasureTable=new Hashtable();
			Vector measureHeader=new Vector();
			LinkedList valueList=new LinkedList();
			String gridCol=null;
			//column
			for(int i=0;i<columnArray.size();i++)
			{
				measureHeader.addElement(columnArray.get(i).toString());
			}
			//data
			for(int j=0;j<dataArray.size();j++)
			{
				JSONArray eachMeasure=(JSONArray)dataArray.get(j);
				for(int k=0;k<eachMeasure.size();k++)
				{
					gridCol=eachMeasure.get(k).toString();
					if(gridCol != null && gridCol.indexOf("$") != -1)
					{
						gridCol=gridCol.substring(0,gridCol.indexOf("$"));
					}
					valueList.add("\""+gridCol+"\"");
				}			
			}
			
			submeasureTable.put(measureHeader, valueList);
			measureTable.put("", submeasureTable);
			list.add(measureTable);
			System.out.println("============list=======print====>>>"+list);
			session.setAttribute("list",list);
			//getServletContext().getRequestDispatcher("/servlet/egurkha.reporter.SaveInCSVFormat").forward(request,response);
			return;
		}
		else if(option.equals("mainCsv"))
		{
			JSONObject resutJSONWhole=resultJson;
			System.out.println("====vresultJsongjhg==>>>"+resutJSONWhole);
			LinkedList list=new LinkedList();		
			Iterator itrInfo=resutJSONWhole.entrySet().iterator();
			boolean commonFieldDisp=true;
			while(itrInfo.hasNext())
			{
				Map.Entry map=(Map.Entry)itrInfo.next();
				String widgetinfo=(String)map.getKey();
				if(widgetinfo.equalsIgnoreCase("selectionDetails") || widgetinfo.equalsIgnoreCase("needNoMeasure") || widgetinfo.equalsIgnoreCase("firstColWordBreakPrint") || widgetinfo.equals("er_sortingColumn"))
					continue;
				JSONObject widgetObj=(JSONObject)resutJSONWhole.get(widgetinfo);
				System.out.println("===key=======>>>>"+widgetinfo+"====value===>>>>>..>>>"+widgetObj);
				Iterator itr2 = widgetObj.entrySet().iterator();
				String dispHeader="";
					while(itr2.hasNext())
					{
						Map.Entry entry2= (Map.Entry)itr2.next();	
						String key=(String)entry2.getKey();
							
						if(key.equalsIgnoreCase("widgetHeader"))
						{
							//widgetHeader=key;
							dispHeader=(String)entry2.getValue();
							continue;
						}
						else if(key.equalsIgnoreCase("widgetFooter"))
						{
							//widgetFooter=key;
							continue;
						}
						else if(key.equalsIgnoreCase("headerDescription"))
						{
							//headerDescription=key;
							continue;
						}
						else if(key.equalsIgnoreCase("widgetHeight"))
						{
							//headerDescription=key;
							continue;
						}
						else if(key.equalsIgnoreCase("adjustWidgetHeight"))
						{
							//headerDescription=key;
							continue;
						}
						else if(key.equalsIgnoreCase("widgetWidth"))
						{
							//headerDescription=key;
							continue;
						}
						else if(key.equalsIgnoreCase("widgetPosition"))
						{
							//headerDescription=key;
							continue;
						}
						else if(key.equalsIgnoreCase("widgetSize"))
						{
							//headerDescription=key;
							continue;
						}
						else if(key.equalsIgnoreCase("DigitalChartCount") || key.equalsIgnoreCase("lineCls"))
						{
							//headerDescription=key;
							continue;
						}
						else
						{
							chart_type=key;
						}
					}
			//	}
			if(chart_type != null && chart_type.equalsIgnoreCase("combinedChart"))
			{
				JSONArray dataSetArry= (JSONArray)widgetObj.get(chart_type);
				JSONObject dataSetObj=(JSONObject)dataSetArry.get(0);
				if(dataSetObj.containsKey("combinedChartCollection"))
				{
					chart_type = "area";
				}
			}
				
					System.out.println("====check====chart_type==>maincsv>>>"+chart_type);
			if(chart_type != null && (chart_type.equalsIgnoreCase("distribution") || chart_type.equalsIgnoreCase("distributedPie") || 
				chart_type.equalsIgnoreCase("stackedbar") || chart_type.equalsIgnoreCase("digital") || chart_type.equalsIgnoreCase("multiDigi") ||
				chart_type.equalsIgnoreCase("topn") || chart_type.equalsIgnoreCase("heatMap") || chart_type.equalsIgnoreCase("combinedChart") || chart_type.equalsIgnoreCase("bar")|| chart_type.equalsIgnoreCase("vertbar")))
			{
				continue;
			}
			
			//..
			if(chart_type != null && "tableWithMergingColumns".equalsIgnoreCase(chart_type))
			{
				chart_type = "table";
			}
			JSONObject widget=new JSONObject();
			if(chart_type!= null && (!chart_type.equalsIgnoreCase("table")))
			{
				resultJson=prepareResultJsonforGridNew(chart_type,widgetinfo,resutJSONWhole,"mainCsv",strUserDateFormat,strShowBy,thisuser);
				//resultJson=prepareResultJsonforGridNew(chart_type,widgetinfo,resultJson,"mainCsv",strUserDateFormat);				
				widget=(JSONObject)resultJson.get("widget");
			}

			if(chart_type!= null && (chart_type.equalsIgnoreCase("table")))
			{
				widget=widgetObj;

			}
			System.out.println("===widget====>>>..>>>sdsfds>>"+widget);
			System.out.println("===resultJson====csv..==>>>..>>>>>>>>"+resultJson);
			//JSONObject widget=(JSONObject)resultJson.get("widget");
		
			JSONArray tableArray=null;
			if(widget != null && widget.containsKey("table"))
			{
				tableArray=(JSONArray)widget.get("table");
			}
			else if(widget != null && widget.containsKey("tableWithMergingColumns"))
			{
				tableArray=(JSONArray)widget.get("tableWithMergingColumns");
			}
			System.out.println("===tableArray===>>>>>>>>>>>>"+tableArray);
			if(tableArray != null && !tableArray.isEmpty())
			{
				JSONObject dataObject=(JSONObject)tableArray.get(0);
				
				System.out.println("=========dataObject========dfd>>>>>"+dataObject);
				//String widgetTitle=dataObject.get("title").toString();
				JSONArray gridCollection=(JSONArray)dataObject.get("gridCollection");
				if(widget.containsKey("tableWithMergingColumns"))
				{
					gridCollection=(JSONArray)dataObject.get("gridCollectionSPO");
				}
				System.out.println("======gridCollection.size...>>>>>>>>"+gridCollection.size());
				
			//	LinkedList list=new LinkedList();		
				if(commonFieldDisp)
				{
				list.add(titleToDisplay);
				list.add(timePeriod);
				}
				
				for(int v=0;v<gridCollection.size();v++)
				{
					JSONArray columnArray=null;
					JSONArray rowExpandColArry=null;
					JSONObject gridObject=(JSONObject)gridCollection.get(v);
					System.out.println("=======chart_type===...>>>ed>>>>>>>>dfdfds>>>"+chart_type);
					if(chart_type!= null && (!chart_type.equalsIgnoreCase("table")))
					{
						columnArray=(JSONArray)gridObject.get("gridColums");
					}
					else
					{
						columnArray=new JSONArray();
						rowExpandColArry=new JSONArray();
						if(gridObject.get("gridColums") != null && gridObject.get("gridColums") instanceof JSONObject)
						{
							JSONObject colObj=(JSONObject)gridObject.get("gridColums");						
							//JSONArray newList=JSONArray ArrayList();
							if(gridObject.get("rowExpander") != null && gridObject.get("rowExpander").toString().equalsIgnoreCase("yes"))
							{
								JSONObject gridColLanguageObj=null;
								if(gridObject.get("gridColLanguageObj") != null)
									gridColLanguageObj=(JSONObject) gridObject.get("gridColLanguageObj");
								Iterator itr=colObj.keys();
								while(itr.hasNext())
								{
									String key=(String)itr.next();
									String headerCol=(String)colObj.get(key);
									if(gridColLanguageObj != null && gridColLanguageObj.get(key) != null)
									{
										headerCol=(String)gridColLanguageObj.get(key);
									}
									columnArray.add(headerCol);
									rowExpandColArry.add(key);
								}
							}
							else
							{
								Iterator itr=colObj.keys();
								while(itr.hasNext())
								{
									String key=(String)itr.next();
									JSONArray functionList=(JSONArray)colObj.get(key);
									if(!functionList.isEmpty())
									{
										for(int f=0;f<functionList.size();f++)
										{
											String eachFun=(String)functionList.get(f);
											columnArray.add(key+"-"+eachFun);
										}
									}
									else
									{
										columnArray.add(key);
									}
									
								}
							}
						}
						else if(gridObject.get("gridColums") != null && gridObject.get("gridColums") instanceof JSONArray)
						{
							columnArray=(JSONArray)gridObject.get("gridColums");
						}
						System.out.println("===columnArray===>>>>..>>"+columnArray);
					}
					JSONArray dataArray=(JSONArray)gridObject.get("gridData");
					//String title=gridObject.get("title").toString();
					//if(title.equals("title"))
						//title=" ";
					/*if(commonFieldDisp)
						list.add(title);*/

					Vector dateVector=new Vector();
					dateVector.add("\""+"Start Date : "+st_dateTime+" hrs\"");
					dateVector.add("\""+"End Date : "+en_dateTime+" hrs\"");		
				if(dataPageNo == null || (dataPageNo != null && Integer.parseInt(dataPageNo) == 1))
				{
				if(commonFieldDisp)
					list.add(dateVector);
				list.add(dispHeader);
				}

					Hashtable measureTable=new Hashtable();
					Hashtable submeasureTable=new Hashtable();
					Vector measureHeader=new Vector();
					LinkedList valueList=new LinkedList();
					//column
					for(int i=0;i<columnArray.size();i++)
					{
						String eachCol=columnArray.get(i).toString();
						if(eachCol != null && eachCol.indexOf("$") != -1)
						{
							eachCol=eachCol.substring(0,eachCol.indexOf("$"));
						}
						if(eachCol != null && eachCol.indexOf("~") != -1)
							eachCol=eachCol.substring(0,eachCol.indexOf("~"));
						if(!eachCol.trim().equals(""))
							measureHeader.addElement(eachCol);
					}
					//data
					if(dataArray != null && dataArray.size() > 0 )
					{
					int headrSze=measureHeader.size();
					for(int j=0;j<dataArray.size();j++)
					{
						if(gridObject.get("rowExpander") != null && gridObject.get("rowExpander").toString().equalsIgnoreCase("yes"))
						{
							Map eachObj=(Map)dataArray.get(j);
							if(rowExpandColArry != null)
							{
								for(int g=0;g<rowExpandColArry.size();g++)
								{
									String eachColKey=(String)rowExpandColArry.get(g);
									String eachColVal=(String)eachObj.get(eachColKey);
									if(eachColVal != null && eachColVal.indexOf("~DDLink") != -1)
									{
										eachColVal=eachColVal.substring(0,eachColVal.indexOf("~DDLink"));
									}
									if(eachColVal != null && eachColVal.indexOf("~DD") != -1)
									{
										eachColVal=eachColVal.substring(0,eachColVal.indexOf("~DD"));
									}
									valueList.add("\""+eachColVal+"\"");
								}
							}
							if(eachObj != null && eachObj.containsKey("subColumnDatas") && eachObj.containsKey("subColumnHeader")){
								JSONArray jsnArr=(JSONArray)eachObj.get("subColumnHeader");
								JSONArray subDataArr=(JSONArray)eachObj.get("subColumnDatas");
								JSONObject subDataObj=null;
								if(jsnArr != null && jsnArr.size() > 0){
									if(measureHeader.size() < jsnArr.size()+1){
										int xtraSize=jsnArr.size()-measureHeader.size()+1;
										if(xtraSize > 0){
											for(int z=0;z<xtraSize;z++){
												measureHeader.add(" ");
											}
										}
									}
									int tmpXtraSize=jsnArr.size()-headrSze+1;
									for(int z=0;z<tmpXtraSize;z++){
										valueList.add("");
									}
									valueList.add(" ");
									for(int z=0;z<jsnArr.size();z++){
										String subColHeader=(String)jsnArr.get(z);
										if(subColHeader != null && subColHeader.indexOf("~") != -1)
											subColHeader=subColHeader.substring(0,subColHeader.indexOf("~"));
										valueList.add(subColHeader);
									}
									for(int z=0;z<subDataArr.size();z++){
										subDataObj=(JSONObject)subDataArr.get(z);
										if(subDataObj != null && subDataObj.size() > 0){
											valueList.add(" ");
											for(int x=0;x<jsnArr.size();x++){
												String strTmp=(String)jsnArr.get(x);
												if(strTmp != null && strTmp.indexOf("~") != -1)
													strTmp=strTmp.substring(0,strTmp.indexOf("~"));
												String strTmpVal=(String)subDataObj.get(strTmp);
												if(strTmpVal != null && strTmpVal.indexOf("~DD") != -1)
													strTmpVal=strTmpVal.substring(0,strTmpVal.indexOf("~DD"));
												if(strTmpVal != null && strTmpVal.indexOf(",") > -1)
													strTmpVal=strTmpVal.replace(","," ");
												valueList.add("\""+strTmpVal+"\"");
											}
										}
									}
								}
							}
						}
						else
						{
							JSONArray eachMeasure=(JSONArray)dataArray.get(j);
							for(int k=0;k<eachMeasure.size();k++)
							{
								String eachData=eachMeasure.get(k).toString();
								if(eachData != null && eachData.indexOf("$") != -1) //.. romove username from each value for userIdleReport
								{
									eachData=eachData.substring(0,eachData.indexOf("$"));
									if(eachData.indexOf("~") != -1)
										eachData=eachData.substring(0,eachData.indexOf("~"));//..remove percentage delemeter(~#f49242~)
								}
								if(eachData != null && eachData.indexOf("~DDLink") != -1)
								{
									eachData=eachData.substring(0,eachData.indexOf("~DDLink"));
								}
								if(eachData != null && eachData.indexOf("~DD") != -1)
								{
									eachData=eachData.substring(0,eachData.indexOf("~DD"));
								}
								
								if(!eachData.trim().equals("iconUserHighIdleTime16") && !eachData.trim().equals("noSymbol"))
									valueList.add("\""+eachData+"\"");
							}	
						}
					}
					
					submeasureTable.put(measureHeader, valueList);
				//measureTable.put(widgetTitle, submeasureTable);//..
				measureTable.put("", submeasureTable);
					list.add(measureTable);
					}
					else
					{
						list=new LinkedList();
						if(needNoMeasure.equals("no"))
							continue;
						if(commonFieldDisp)
						{
						list.add(titleToDisplay);
						list.add(timePeriod);
						}
						dateVector=new Vector();
						dateVector.add("\""+"Start Date : "+st_dateTime+" hrs\"");
						dateVector.add("\""+"End Date : "+en_dateTime+" hrs\"");		
						if(commonFieldDisp)
							list.add(dateVector);
						list.add(dispHeader);
						list.add("No Measure Available");
						list.add("");
					}				
				}
			}
			else
			{
				if(needNoMeasure.equals("no"))
					continue;
				if(commonFieldDisp)
				{
				list.add(titleToDisplay);
				list.add(timePeriod);
				}
				Vector dateVector=new Vector();
				dateVector.add("\""+"Start Date : "+st_dateTime+" hrs\"");
				dateVector.add("\""+"End Date : "+en_dateTime+" hrs\"");		
				if(commonFieldDisp)
					list.add(dateVector);
				list.add(dispHeader);
				list.add("No Measure Available");
				list.add("");
			}
			commonFieldDisp=false;
			
		}
			System.out.println("============list===main====print====>>>"+list);
			session.setAttribute("list",list);
			if(scheduleMailFormat != null && scheduleMailFormat.equalsIgnoreCase("csv"))
				session.setAttribute("ScheduleCSVData",list);
			//else
			//getServletContext().getRequestDispatcher("/servlet/egurkha.reporter.SaveInCSVFormat").forward(request,response);
			return;
		}
	}	
	

	if(widgetIdInfo!=null)
	{

		graphIndex = (String)request.getParameter("graphIndex");
		if(fromdistributedPie!=null && fromdistributedPie.equalsIgnoreCase("yes"))
		{
			Map distributedPieMap =(HashMap)session.getAttribute("distributedPieMap");
			Map distributedPieinfo=(HashMap)distributedPieMap.get(widgetIdInfo);
			List distributedPieDbInfo=(ArrayList)distributedPieinfo.get("data");
			String distributedPieGroup=(String)distributedPieinfo.get("groupBy");
			String head=(String)distributedPieinfo.get("widgetHeader");
			String foot=(String)distributedPieinfo.get("widgetFooter");
			String widgetTitle=(String)distributedPieinfo.get("headerDescription");
			String range=(String)request.getParameter("Range");
			List selectedPieList=(ArrayList)distributedPieDbInfo.get(Integer.parseInt(graphIndex));
			System.out.println("distributedPieMap======>>>>>>>>>"+selectedPieList);
			resultJson=prepareResultJsonPieToGrid(selectedPieList,distributedPieGroup,range,head,foot,widgetTitle);
		}
		else
		{
			System.out.println("==printBy=====final==>>>"+printBy);
			if(printBy!=null)
			{

			}
			else
			{
				resultJson=prepareResultJsonforGrid(chart_type,widgetIdInfo,resultJson,Integer.parseInt(graphIndex),strUserDateFormat,
					sessionCompName,thisuser);
				System.out.println("seperate===cchartda========>>>>>>>>>"+resultJson);
			}
		}
	}
	
	if(resultJson == null)
	{
		if(request.getParameter("dataDrill") != null)
		{
			String dataDrill=(String)request.getParameter("dataDrill");
			if(dataDrill.equals("yes"))
				resultJson = (JSONObject) session.getAttribute("htdataDrillDown");
		}
		else
			resultJson = (JSONObject) session.getAttribute("htdata");
		
	}
	//..
	
	if((dbInfo.doubleByteEnabled || !thisuser.getLanguage().equals("en_US")) && !(pdfPrint !=null && pdfPrint.equalsIgnoreCase("yes")))
	{
		fontStyleDbl = " multi_font";
		fontStyleDblSingl = "multi_font";
	}
	else
	{
		fontStyleDbl = "";
		fontStyleDblSingl = "";
	}
	if(titleToDisplay==null || titleToDisplay.equalsIgnoreCase("undefined"))
		titleToDisplay="eG Custom Report";
	if(titleToDisplay != null && titleToDisplay.indexOf(".") != -1)
	{
		titleToDisplay=titleToDisplay.substring(titleToDisplay.lastIndexOf(".")+1);
	}
	titleToDisplay = utils.specialCharDecode(titleToDisplay);
%>
<html>
<head>
	<style>
		#only-table span.decimal-align{float: left; text-align: right; width:50%}
		#only-table span.decimal-align2{float: right; text-align: left; width:50%}
	</style>
	<%
	if(pdfPrint !=null && pdfPrint.equalsIgnoreCase("yes"))
	{
	%>
	<title>&nbsp; <egui:intnl text="reporter.common.Reporter" />&nbsp; &nbsp;-PDR- &nbsp;</title>
	<%
	}
	else
	{
	%>
	<title><%=titleToDisplay%></title>
	<%
	}
	%>
	<meta http-equiv="refresh">
	<link rel="stylesheet" type="text/css" href="../../final/styles/eGLightThemeIcons.css" />
	<link rel="stylesheet" type="text/css" href="../../final/reporter/styles/printpagestyle.css" />
</head>
<body marginwidth="20" marginheight="20" bgcolor="#FFFFFF">
	<%
		String strLogCls = "printHeaderBoxLogo";
		if(pdfPrint !=null && pdfPrint.equalsIgnoreCase("yes"))
		{
			strLogCls = "printHeaderBoxLogo";
		}
		else
			strLogCls = "printPdfHeaderBoxLogo";

		if(pdfPrint !=null && pdfPrint.equalsIgnoreCase("yes"))
		{
	%>
			<div class="<%=strLogCls%>" style="padding-top:10px"><img src="<%=imageName%>" border="0" /></div>
	<%
		}
		else
		{
	%>
			<div class="<%=strLogCls%>"><img src="<%=imageName%>" border="0" /></div>
	<%
		}
	%>
	
	<div class="printHeaderBox">
	<% 
	if (!StringUtils.isNull(titleToDisplay))
	{ 
		%>
		<div class="printHeaderBoxTitle"><%=titleToDisplay%></div>
		<%
	}
	else
	{ 
		%>
		<div class="printHeaderBoxTitle"><egui:intnl text="reporter.common.Report Builder" /></div>
		<%
	}

	if(pdfPrint !=null && pdfPrint.equalsIgnoreCase("yes"))
	{
	%>
		<div class="printHeaderBoxPrintIcon"><img class="iconPrinter mouse"  id="pri ntbt" src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" border="0" onClick="javascript:window.print()" alt='<egui:intnl text="reporter.common.PRINT"/>' title='<egui:intnl text="reporter.common.PRINT"/>'/></div>
	<%
	}
	%>
	</div>
	<div class="printOuterBoxNoBorder"> 
	<%
	if(selDetails != null)
	{
		if(selDetails.get("Analysis By") != null)
		{
			%>
			<div class="printSelectionFields">Analysis By: <b><%=selDetails.get("Analysis By")%></b></div>
			<%
		}
		if(selDetails.get("Component Type") != null)
		{
			%>
			<div class="printSelectionFields">Component Type: <b><%=selDetails.get("Component Type")%></b></div>
			<%
		}		
		if(selDetails.get("Component") != null)
		{
			%>
			<div class="printSelectionFields">Component: <b><%=selDetails.get("Component")%></b></div>
			<%
		}		
		if(selDetails.get("Time Period") != null)
		{
			%>
			<div class="printSelectionFields">Time Period: <b><%=selDetails.get("Time Period")%></b></div>
			<%
		}		
	}
	%>
	<div class="printSelectionFields">Timeline - <span class="bold"><%=st_dateTime%> to <%=en_dateTime%></span></div>
	<%
	if(tempDesc.length()>0)
	{
		%>
			<div class="printSelectionFields"><%=tempDesc%></div>
		<%
	}
	%>
	</div>
<%
	int cnt=0;
	JSONObject sessionChartCollecton=new JSONObject();
	boolean dataAvailable=false;
	System.out.println("=resultJson====final>>>>>>>>"+resultJson);
	System.out.println("=strShowBy====final>>>>>>>>"+strShowBy);
	if(strShowBy!=null && strShowBy.equalsIgnoreCase("componentWise"))
	{
		if(resultJson!=null && resultJson.size()>0)
		{
			Iterator itr1 = resultJson.entrySet().iterator();
			JSONArray widgetWiseAry = new JSONArray();
			JSONObject widgetComponentWiseObj = new JSONObject();
			while(itr1.hasNext())
			{
				Map.Entry entry1 = (Map.Entry)itr1.next();	
				String widget=(String)entry1.getKey();
				if(widget.equals("templateTitle") || widget.equals("selectionDetails") || widget.equals("needNoMeasure") || widget.equals("firstColWordBreakPrint") || widget.equals("er_sortingColumn"))
				{
					continue;
				}
				System.out.println("===widget======?>>>>>"+widget+"==widgetIdInfo======?hhhh/==>>>"+widgetIdInfo);
				if(printBy!=null && printBy.length()>0 && !widget.equalsIgnoreCase(widgetIdInfo))
				{
					//System.out.println("===widget====11==?>>>>>"+widget+"==widgetIdInfo=11=====?hhhh/==>>>"+widgetIdInfo);
					continue;
				}
				System.out.println("widget:::  "+widget);
				JSONObject widgetCollection=(JSONObject) resultJson.get(widget);
				Iterator itr2 = widgetCollection.entrySet().iterator();
				JSONObject widgetWiseObj = new JSONObject();
				JSONObject chartCollecton=new JSONObject();
				String widgetHeader="";
				String widgetFooter="";
				String headerDescription="";
				System.out.println("===widgetCollection==>>>..>dd>>>"+widgetCollection);
				while(itr2.hasNext())
				{
					Map.Entry entry2= (Map.Entry)itr2.next();	
					String chartType=(String)entry2.getKey();
					System.out.println("chartTypechartType::: 1111 "+chartType);
					if(chartType.equalsIgnoreCase("widgetHeader"))
					{
						widgetHeader=(String)widgetCollection.get(chartType);
						widgetWiseObj.put("widgetHeader",widgetHeader);
						continue;
					}
					if(chartType.equalsIgnoreCase("widgetFooter"))
					{
						widgetFooter=(String)widgetCollection.get(chartType);
						widgetWiseObj.put("widgetFooter",widgetFooter);
						continue;
					}
					if(chartType.equalsIgnoreCase("headerDescription"))
					{
						headerDescription=(String)widgetCollection.get(chartType);
						widgetWiseObj.put("headerDescription",headerDescription);
						continue;
					}
					if(chartType.equalsIgnoreCase("widgetHeight"))
					{
						//headerDescription=key;
						continue;
					}
					if(chartType.equalsIgnoreCase("adjustWidgetHeight"))
					{
						//headerDescription=key;
						continue;
					}
					if(chartType.equalsIgnoreCase("widgetWidth"))
					{
						//headerDescription=key;
						continue;
					}
					if(chartType.equalsIgnoreCase("widgetPosition"))
					{
						//headerDescription=key;
						continue;
					}	
					if(chartType.equalsIgnoreCase("widgetSize"))
					{
						//headerDescription=key;
						continue;
					}	
					if(chartType.equalsIgnoreCase("DigitalChartCount") || chartType.equalsIgnoreCase("lineCls"))
						continue;
					if(widgetHeader!=null && widgetHeader.length()==0)
						widgetHeader=(String)widgetCollection.get("widgetHeader");
					if(widgetFooter!=null&& widgetFooter.length()==0)
						widgetFooter=(String)widgetCollection.get("widgetFooter");
					if(headerDescription!=null&& headerDescription.length()==0)
						headerDescription=(String)widgetCollection.get("headerDescription");
					JSONObject dataobject= null;
					JSONArray tempCompdataArray=(JSONArray) widgetCollection.get(chartType);
					if(tempCompdataArray!=null && tempCompdataArray.size()>0)
					{
						dataobject = (JSONObject) tempCompdataArray.get(0);
					}
					if(dataobject!=null && dataobject.size()>0 && chartType!=null )
					{
						String colKey="barChartCollection";
						if(chartType.equalsIgnoreCase("stackedbar"))
						{
							colKey="stackedBarChartCollection";
						}
						if(chartType.equalsIgnoreCase("distribution"))
						{
							colKey="distributionChartCollection";
						}
						if(chartType.equalsIgnoreCase("timeline"))
						{
							colKey="timelineChartCollection";
						}
						if(chartType.equalsIgnoreCase("area"))
						{
							colKey="timelineChartCollection";
						}
						if(chartType.equalsIgnoreCase("barHistogram"))
						{
							colKey="barHistogramChartCollection";
						}
						if(chartType.equalsIgnoreCase("distributedPie"))
						{
							colKey="distributedPieChartCollection";
						}
						if(chartType.equalsIgnoreCase("table"))
						{
							colKey="gridCollection";
						}
						if(chartType.equalsIgnoreCase("topn"))
						{
							colKey="topnCollection";
						}
						if(chartType.equalsIgnoreCase("heatMap"))
						{
							colKey="heatMapChartCollection";
						}
						JSONObject dataComponentArray = (JSONObject)dataobject.get(colKey);
						if(dataComponentArray!=null && dataComponentArray.size()>0)
						{
							Iterator itr3 = dataComponentArray.entrySet().iterator();
							while(itr3.hasNext())
							{
								Map.Entry entry3= (Map.Entry)itr3.next();	
								String chartname=(String)entry3.getKey();
								cnt = 0;
								chartCollecton=new JSONObject();
								JSONArray dataArray =(JSONArray)dataComponentArray.get(chartname);
								if(printBy!=null && printBy.length()>0 )
								{
									//System.out.println("sessionCompName "+sessionCompName);
									//System.out.println("chartname "+chartname);
									if(!chartname.equalsIgnoreCase(sessionCompName))
										continue;
									if(dataArray!=null && dataArray.size()>0)
									{
										//for(int kk=0;kk<dataArray.size();kk++)
										//{
											JSONObject gridObj = (JSONObject)dataArray.get(Integer.parseInt(graphIndex));
											if(gridObj != null && gridObj.get("chartType") != null)
											{
												chartType=(String)gridObj.get("chartType");											
											}											
											chartCollecton.put(chartType+"_"+chartname+"_"+cnt,gridObj);
											gridObj.put("title","");
											sessionChartCollecton.put(chartType+"_"+chartname+"_"+cnt,gridObj);
											cnt++;
											dataAvailable=true;
										//}
										widgetWiseObj.put("chartCollecton",chartCollecton);
									}
								}
								else
								{
									if(dataArray!=null && dataArray.size()>0)
									{
										for(int kk=0;kk<dataArray.size();kk++)
										{
											JSONObject gridObj = (JSONObject)dataArray.get(kk);
											if(gridObj != null && gridObj.get("chartType") != null)
											{
												chartType=(String)gridObj.get("chartType");											
											}											
											chartCollecton.put(chartType+"_"+chartname+"_"+cnt,gridObj);
											gridObj.put("title","");
											sessionChartCollecton.put(chartType+"_"+chartname+"_"+cnt,gridObj);
											cnt++;
											dataAvailable=true;
										}
										widgetWiseObj.put("chartCollecton",chartCollecton);
									}
								}
								widgetComponentWiseObj.put(chartname,widgetWiseObj);
							}
						}
					}
				}
				widgetWiseAry.add(widgetComponentWiseObj);
			}
			System.out.println("widgetWiseAry _____[1111]_____ "+widgetWiseAry);
			if(widgetWiseAry!=null && widgetWiseAry.size()>0)
			{
				session.setAttribute("chartCollecton",sessionChartCollecton);
				session.setAttribute("ScheduleCSVData",sessionChartCollecton);
				for(int k=0;k<widgetWiseAry.size();k++)
				{
					JSONObject jobjectCompoent = (JSONObject)widgetWiseAry.get(k);
					Iterator itr4 = jobjectCompoent.entrySet().iterator();
					while(itr4.hasNext())
					{
						Map.Entry entry3= (Map.Entry)itr4.next();	
						String compName = (String)entry3.getKey();
						JSONObject widgetWiseObj=(JSONObject)jobjectCompoent.get(compName);
						JSONObject chartCollecton =(JSONObject) widgetWiseObj.get("chartCollecton");
						if(chartCollecton==null)
							continue;
						System.out.println("chartCollecton ___________"+chartCollecton);
%>					
					<div class="clearDiv"></div>
					<div class="printOuterBox">
						<div class="printOuterBoxHeader"><%=compName%></div>
<%
						String widgetHeader=(String)widgetWiseObj.get("widgetHeader");
						String widgetFooter=(String)widgetWiseObj.get("widgetFooter"); 
						String headerDescription=(String)widgetWiseObj.get("headerDescription");
						//System.out.println("chartCollecton::::::::::::::::::   "+chartCollecton);
						String queryString="";
							queryString="/final/servlet/com.eg.ErReportBuilderController;jsessionid="+session.getId()+"?forChartImage=yes&showLegendsEnable="+request.getParameter("showLegendsEnable");
						Iterator itr2 = chartCollecton.entrySet().iterator();
						Iterator itrBefore = chartCollecton.entrySet().iterator();
						int noOfCharts=chartCollecton.size();
						int num=0;
						int headerColSapn=2;
						boolean isGraph=true;
						if(noOfCharts==1){
							 headerColSapn=1;
							while(itrBefore.hasNext())
							{
								Map.Entry entryBefore= (Map.Entry)itrBefore.next();	
								String chartKey=(String)entryBefore.getKey();
								System.out.println("chartKeyBefore::::::::::::::::::   "+chartKey);
								if(chartKey.contains("table")||chartKey.contains("topn") || chartKey.contains("heatMap"))
								{
									isGraph=false;
								}
							}
						}
							if(isGraph){
			%>
						<table align="center" cellspacing="0" cellpadding="0" border="0"  width="100%" style="padding:5px 5px 5px 5px">
			<%
							}
						
						String strImgWidth="400";
						String strGraphHeight="200";
						if(noOfCharts==1)
							strImgWidth="700";
					while(itr2.hasNext())
					{
						String sentQuery="";
						Map.Entry entry2= (Map.Entry)itr2.next();	
						String chartKey=(String)entry2.getKey();
						System.out.println("chartKeyBefore::::::::::::::::::   "+chartKey);	
						JSONObject chartObject = (JSONObject)chartCollecton.get(chartKey);
						System.out.println("chartObject::::::::::::::::::   "+chartObject);
						if(chartKey.contains("table")||chartKey.contains("topn"))
						{
							String graphHeader = (String)chartObject.get("graphHeader");
							String graphFooter = (String)chartObject.get("graphFooter");
							if(graphHeader==null||graphHeader.length()==0)
							{
								graphHeader=(String)chartObject.get("title");
							}
							if(graphFooter==null||graphFooter.length()==0)
							{
								graphFooter=widgetFooter;
							}
							JSONObject gridObj=(JSONObject) chartCollecton.get(chartKey);
							if(gridObj!=null && gridObj.size()>0)
							{
								String title=(String) gridObj.get("title");
								if(title==null)
									title="";
								JSONArray gridData=(JSONArray) gridObj.get("gridData");
								Object gridColums_temp= gridObj.get("gridColums");
								if(gridColums_temp instanceof JSONArray)
								{
									JSONArray gridColums=(JSONArray) gridObj.get("gridColums");
									System.out.println("instance of array");
			%>
								<table align="center" cellspacing="0" cellpadding="0" width="100%" class="gridTable"><col width="25%">
									<tr>
										<!-- <td colspan="<%=gridColums.size() %>" class="printTableHeader" ><%=title %></td> -->
										<td colspan="<%=gridColums.size() %>" class="printTableHeader" ><%=graphHeader%></td>
									</tr>
									<tr>
				<%
									for(int tk=0;tk<gridColums.size();tk++)
									{
										String str=(String) gridColums.get(tk);	
				%>
											<th><%=str %></th>
				<%
									}
				%>
									</tr>			
			<%								
									for(int tk=0;tk<gridData.size();tk++)
									{
										JSONArray strArr=(JSONArray) gridData.get(tk);
										if(strArr!=null &&strArr.size()>0)
											{
				%>
										<tr>			
				<%	
											for(int jk=0;jk<strArr.size();jk++)
											{
												String str=(String) strArr.get(jk);	
												//System.out.println("========str====am comimg========>>>>>>>>>>>"+str);
												if(str.indexOf("~")>-1 && str.indexOf("~#~")==-1)
												{
													//System.out.println("========str====am comimg here also========>>>>>>>>>>>"+str);
													String valueAry[]=str.split("~");
													String barStr = "<table width='" + valueAry[2] + "' cellpadding='0' cellspacing='0' border='0'  height='8' class='prog_border'>";
													//barStr += "<tr>";
													//barStr += "<td align='left' width='100%' height='8' style='padding:0px'>";
													//barStr += "<table height='8'  cellpadding='0' cellspacing='0' border='0'>";
													barStr += "<tr>";
													barStr += "<td class='reporterProgressBar' width='" + valueAry[2] + "'  style='background:"+valueAry[1]+";padding:0px;height:8px'> </td>";
													barStr += "</tr>";
													//barStr += "</table>";
													//barStr += "</td>";
													//barStr += "</tr>";
													barStr += "</table>";
													str = "<table width='100%' cellpadding='0' cellspacing='0' border='0px'><tr><td style='padding:0px 20px 0px 0px;width:200px;border:0px' class='font_normal11'>" + valueAry[0] + "</td><td style='padding:0px;height:10px;border:0px'>" + barStr + "</td></tr></table>";
												}
												else if(str.indexOf(" week")>-1)
												{
													str=getDataForWeekGroup(str);
												}
					%>
											<td><%=str %></td>
					<%
											}									
					%>
										</tr>			
					<%	
												}
											}
			%>
							</table>
			<%
					}
					else
					{
						System.out.println("instance of object");
						JSONObject gridColumsObj=(JSONObject) gridObj.get("gridColums");
						JSONArray dataAry=(JSONArray) gridData.get(0);
						ArrayList subColList = new ArrayList();
						Iterator iter = gridColumsObj.entrySet().iterator();
			%> 		
					<table align="center" cellspacing="0" cellpadding="0" width="97%" class="gridTable"><col width="25%">
					<tr>
						<td colspan="<%=dataAry.size()%>" class="printTableHeader"  align="center" ><%=graphHeader%></td>
					</tr>
					<tr>
			<%
					 while(iter.hasNext())
					{
						Map.Entry entryItr= (Map.Entry)iter.next();	
						String mainCol=(String)entryItr.getKey();
						JSONArray mainColAry = (JSONArray) gridColumsObj.get(mainCol);
						String settingInfo=" rowspan='2' ";
						if(mainColAry.size()>0)
						{
							settingInfo= " colspan='"+mainColAry.size()+"' ";
							for(int rv = 0;rv<mainColAry.size();rv++)
							{
								subColList.add(mainColAry.get(rv));
							}
						}
						%>
							<th <%=settingInfo%> class="printTableHeader" ><%=mainCol%></th>
						<%
					}
			%>
					</tr>
			<%
					if(subColList.size()>0)
					{
			%>
					<tr>
			<%
					for(int tk=0;tk<subColList.size();tk++)
					{
						String str=(String) subColList.get(tk);	
			%>
						<th class="subHeader"><%=str %></th>
			<%
					}
			%>
					</tr>
			<%
					}		
			%>
			<%								
					for(int tk=0;tk<gridData.size();tk++)
					{
						JSONArray strArr=(JSONArray) gridData.get(tk);
						if(strArr!=null &&strArr.size()>0)
							{
			%>
							<tr>			
			<%	
									for(int jk=0;jk<strArr.size();jk++)
									{
										String str=(String) strArr.get(jk);	
										if(str.indexOf(" week")>-1)
										{
											str=getDataForWeekGroup(str);
										}
										//System.out.println("========str============>>>>>>>>>>>"+str);
			%>
									<td><%=str %></td>
			<%
									}									
			%>
								</tr>			
			<%	
								}
							}
			%>
							</table>
			<%
						}
					}
						}
						else
						{
						sentQuery=	queryString+"&chartKey="+com.eg.EgURLEncoder.encode(chartKey,"UTF-8");
						System.out.println("queryStringqueryString="+sentQuery);
						String graphHeader = (String)chartObject.get("graphHeader");
						String graphFooter = (String)chartObject.get("graphFooter");
						if(graphHeader==null||graphHeader.length()==0)
						{
							graphHeader=(String)chartObject.get("title");
						}
						if(graphFooter==null||graphFooter.length()==0)
						{
							graphFooter=widgetFooter;
						}
						if(num==0)			
						{				
			%>
								<tr>
			<%				
						}			
			%>				
							<td id="cellbgwhite" style="padding:0px 10px 10px 0px">
								<div class="printOuterBox">
								<!--<table align="center" cellspacing="0" cellpadding=""  width="100%" class="printTable" >-->
								<div class="printOuterBoxHeader"><%=graphHeader%></div>
								<div style="width:100%;overflow:auto;padding:10px">	
									<img src="<%=sentQuery%>&optt=graph&er_width=<%=strImgWidth%>&er_height=<%=strGraphHeight%>&er_view=IMAGE" border="0" hspace="0"  vspace="0" ></img>
								</div>
			<%
										if(graphFooter!=null && !graphFooter.equalsIgnoreCase("Notes"))
										{
			%>
										<br/>
										<div class="printFooterText"><%=graphFooter%></div>
			<%
										}
			%>
								</div>
							</td>					
			<%			if(num!=0)			
						{
							num=0;
			%>
								</tr>
							
			<%				
						}
						else
							num++;
						}
					}
					if(noOfCharts!=1&&noOfCharts%2==1)
					{
			%>
						<td></td></tr>
			<%
					}
					if(isGraph){
			%>
							</table>
			<%
						}
%>
					</td>
					</div>
					<br/>
					
<%
					}
				}
			}
		}
	}
	else
	{
	if(resultJson!=null && resultJson.size()>0)
	{
		Iterator itr1 = resultJson.entrySet().iterator();
		JSONArray widgetWiseAry = new JSONArray();
		while(itr1.hasNext())
		{
			Map.Entry entry1 = (Map.Entry)itr1.next();	
			String widget=(String)entry1.getKey();
				if(widget.equals("templateTitle") || widget.equals("selectionDetails") || widget.equals("needNoMeasure") || widget.equals("firstColWordBreakPrint") || widget.equals("er_sortingColumn"))
			{
				continue;
			}
			System.out.println("===widget======?>>>>>"+widget+"==widgetIdInfo======?hhhh/==>>>"+widgetIdInfo);
			if(printBy!=null && printBy.length()>0 && !widget.equalsIgnoreCase(widgetIdInfo))
			{
				//System.out.println("===widget====11==?>>>>>"+widget+"==widgetIdInfo=11=====?hhhh/==>>>"+widgetIdInfo);
				continue;
			}
			System.out.println("widget:::  "+widget);
			JSONObject widgetCollection=(JSONObject) resultJson.get(widget);
			Iterator itr2 = widgetCollection.entrySet().iterator();
			JSONObject widgetWiseObj = new JSONObject();
			JSONObject chartCollecton=new JSONObject();
			String widgetHeader="";
			String widgetFooter="";
			String headerDescription="";
			System.out.println("===widgetCollection==>>>..>>>>"+widgetCollection);
			while(itr2.hasNext())
			{
				Map.Entry entry2= (Map.Entry)itr2.next();	
				String chartType=(String)entry2.getKey();
				System.out.println("chartTypechartType:::  "+chartType);
				if(chartType.equalsIgnoreCase("widgetHeader"))
				{
					widgetHeader=(String)widgetCollection.get(chartType);
					widgetWiseObj.put("widgetHeader",widgetHeader);
					continue;
				}
				if(chartType.equalsIgnoreCase("widgetFooter"))
				{
					widgetFooter=(String)widgetCollection.get(chartType);
					widgetWiseObj.put("widgetFooter",widgetFooter);
					continue;
				}
				if(chartType.equalsIgnoreCase("headerDescription"))
				{
					headerDescription=(String)widgetCollection.get(chartType);
					widgetWiseObj.put("headerDescription",headerDescription);
					continue;
				}
			   	if(chartType.equalsIgnoreCase("widgetHeight"))
				{
					//headerDescription=key;
					continue;
				}
					if(chartType.equalsIgnoreCase("adjustWidgetHeight"))
					{
						//headerDescription=key;
						continue;
					}
				if(chartType.equalsIgnoreCase("widgetWidth"))
				{
					//headerDescription=key;
					continue;
				}
				if(chartType.equalsIgnoreCase("widgetPosition"))
				{
					//headerDescription=key;
					continue;
				}
				if(chartType.equalsIgnoreCase("widgetSize"))
				{
					//headerDescription=key;
					continue;
				}
				if(chartType.equalsIgnoreCase("DigitalChartCount") || chartType.equalsIgnoreCase("lineCls"))
					continue;
				if(widgetHeader!=null && widgetHeader.length()==0)
					widgetHeader=(String)widgetCollection.get("widgetHeader");
				
				if(widgetFooter!=null&& widgetFooter.length()==0)
					widgetFooter=(String)widgetCollection.get("widgetFooter");

				if(headerDescription!=null&& headerDescription.length()==0)
					headerDescription=(String)widgetCollection.get("headerDescription");

				JSONArray dataArray=(JSONArray) widgetCollection.get(chartType);
				if(dataArray!=null && dataArray.size()>0 && chartType!=null )
				{
					String colKey="barChartCollection";
					if(chartType.equalsIgnoreCase("stackedbar"))
					{
						colKey="stackedBarChartCollection";
					}
					if(chartType.equalsIgnoreCase("verticalstackedbar"))
					{
						colKey="stackedBarChartCollection";
					}
					if(chartType.equalsIgnoreCase("distribution"))
					{
						colKey="distributionChartCollection";
					}
					if(chartType.equalsIgnoreCase("timeline"))
					{
						colKey="timelineChartCollection";
					}
					if(chartType.equalsIgnoreCase("area"))
					{
						colKey="timelineChartCollection";
					}
					if(chartType.equalsIgnoreCase("barHistogram"))
					{
						colKey="barHistogramChartCollection";
					}
					if(chartType.equalsIgnoreCase("distributedPie"))
					{
						colKey="distributedPieChartCollection";
					}
					if(chartType.equalsIgnoreCase("table"))
					{
						colKey="gridCollection";
					}
					if(chartType.equalsIgnoreCase("topn"))
					{
						colKey="topnCollection";
					}
					if(chartType.equalsIgnoreCase("heatMap"))
					{
						colKey="heatMapChartCollection";
					}
					if(chartType.equalsIgnoreCase("combinedChart"))
					{
						colKey="combinedChartCollection";
					}
						
					if(printBy!=null && printBy.length()>0 )
					{
						for(int i=0;i<dataArray.size();i++)
						{
							JSONObject dataObj=(JSONObject) dataArray.get(i);
							JSONArray gridCollection=(JSONArray)dataObj.get(colKey);
							//for(int j=0;j<gridCollection.size();j++)
							//{
							if(gridCollection != null && gridCollection.size() > 0)
							{
								JSONObject gridObj=(JSONObject) gridCollection.get(Integer.parseInt(graphIndex));
								if(gridObj != null && gridObj.get("chartType") != null)
								{
									if(gridObj.get("chartType").toString().equalsIgnoreCase("bar"))
									{
										chartType="bar";
									}
								}
								sessionChartCollecton.put(chartType+"_0",gridObj);
								chartCollecton.put(chartType+"_0",gridObj);
							}
							else
							{
							%>
								<table align="center" width="97%" cellspacing="0" cellpadding="4"   border="0">
									<tr>
										<table width='100%' height='100%'><tr>	<td align='center' valign='middle'><img src='../images/Light/nomeasures_custom.png' /></td></tr></table>
									</tr>
								</table>
							<%
							}
							//chartCollecton.put(chartType+"_"+cnt,gridObj);
								//cnt++;
							//}
						}
					}
					else
					{
						
						for(int i=0;i<dataArray.size();i++)
						{
							JSONObject dataObj=(JSONObject) dataArray.get(i);
							JSONArray gridCollection=(JSONArray)dataObj.get(colKey);
							for(int j=0;j<gridCollection.size();j++)
							{
								JSONObject gridObj=(JSONObject) gridCollection.get(j);
								if(gridObj != null && gridObj.get("chartType") != null)
								{
									if(gridObj.get("chartType").toString().equalsIgnoreCase("bar"))
									{
										chartType="bar";
									}
								}
								sessionChartCollecton.put(chartType+"_"+cnt,gridObj);
								chartCollecton.put(chartType+"_"+cnt,gridObj);
								cnt++;
							}
						}
					}
					widgetWiseObj.put("chartCollecton",chartCollecton);
					dataAvailable=true;
				}
			}
			widgetWiseAry.add(widgetWiseObj);
		}
		System.out.println("widgetWiseAry==== "+widgetWiseAry);
		session.setAttribute("chartCollecton",sessionChartCollecton);
		session.setAttribute("ScheduleCSVData",sessionChartCollecton);
		for(int k=0;k<widgetWiseAry.size();k++)
		{
			JSONObject widgetWiseObj=(JSONObject)widgetWiseAry.get(k);
			JSONObject chartCollecton =(JSONObject) widgetWiseObj.get("chartCollecton");
			if(chartCollecton==null)
				continue;
			String widgetHeader=(String)widgetWiseObj.get("widgetHeader");
			String widgetFooter=(String)widgetWiseObj.get("widgetFooter"); 
			String headerDescription=(String)widgetWiseObj.get("headerDescription");
			//System.out.println("chartCollecton::::::::::::::::::   "+chartCollecton);
			String queryString="";
			
				queryString="/final/servlet/com.eg.ErReportBuilderController;jsessionid="+session.getId()+"?forChartImage=yes&showLegendsEnable="+request.getParameter("showLegendsEnable");
			Iterator itr2 = chartCollecton.entrySet().iterator();
			Iterator itrBefore = chartCollecton.entrySet().iterator();
			int noOfCharts=chartCollecton.size();
			int num=0;
				int headerColSapn=2;
				boolean isGraph=true;
				if(noOfCharts==1){
					 headerColSapn=1;
					while(itrBefore.hasNext())
					{
						Map.Entry entryBefore= (Map.Entry)itrBefore.next();	
						String chartKey=(String)entryBefore.getKey();
						System.out.println("chartKeyBefore::::::::::::::::::   "+chartKey);
						if(chartKey.contains("table")||chartKey.contains("topn") || chartKey.contains("heatMap"))
						{
							isGraph=false;
						}
					}
				}
					if(isGraph){
%>
				<div class="clearDiv"></div>
				<table width="100%" >
				<!--<table align="center" cellspacing="0" cellpadding="0" border="0"  width="97%">-->
				
	<%
					}
	%>
					<!-- <table width="97%"  class=""  cellspacing="0" cellpadding="0" border="0" align="center" bgcolor="#FFFFFF" > -->
<%				
			String strImgWidth="400";
			String strGraphHeight="200";
			if(noOfCharts==1)
				strImgWidth="700";
		while(itr2.hasNext())
		{
			String sentQuery="";
			Map.Entry entry2= (Map.Entry)itr2.next();	
			String chartKey=(String)entry2.getKey();
				JSONObject chartObject = (JSONObject)chartCollecton.get(chartKey);
				System.out.println("chartKey::::::::::::::::::   "+chartKey);
				System.out.println("chartObject:::::::::::::fdgd:::::   "+chartObject);
				if(chartKey.contains("heatMap"))
			{
					System.out.println("=======11111111heatmap=sdf===dfdsfds===>>>>>");
					%>
					<table border="1" id="heatMaphtml" class="tableBorderHtml" align="center" width="100%" height="100%">
						<tbody>
							<tr>
								<th align="center" class="theadBorderHtml" style="padding-left: 10px;"></th>
<%
									JSONArray xAxisLabel=(JSONArray)chartObject.get("xAxisLabel");
									System.out.println("===xAxisLabel===>>>>>>>>>sfds>>>dd>>>>>>>"+xAxisLabel);
									for(int i=0;i<xAxisLabel.size();i++)
									{
										String xAxisdate=(String)xAxisLabel.get(i);
										%>
										<th align="center" class="theadBorderHtml" style="padding-left: 10px;"><%=xAxisdate%></th>
										<%
									}
%>
							</tr>
<%
								JSONArray dataSetArry=(JSONArray)chartObject.get("DataSet");
								for(int j=0;j<dataSetArry.size();j++)
								{
									JSONObject eachObj=(JSONObject)dataSetArry.get(j);
									String objName=(String)eachObj.get("name");
									JSONArray dataArry=(JSONArray)eachObj.get("data");
										%>
										<tr style="padding-left: 10px;">
										<%
										String ddd="<td style='background-color:#ffffff;'>"+objName+"</td>";
										for(int k1=0;k1<dataArry.size();k1++)
										{
											String data=(String)dataArry.get(k1);
											String colorr="green";
											if(data != null && data.indexOf("$$") != -1)
											{
												colorr=data.substring(data.indexOf("$$")+2);
												data=data.substring(0,data.indexOf("$$"));
											}
											ddd+="<td align='center' style='background-color:"+colorr+"'>";
											ddd+="<span class='font_bold11'>"+data+"</span></td>";
										}
										%>
										<%=ddd%>
										</tr>
								<%
								}
							%>
						</tbody>
					</table>
<%
				}
				else if(chartKey.contains("table")|| chartKey.contains("topn"))
				{
					String graphHeader = (String)chartObject.get("graphHeader");
					String graphFooter = (String)chartObject.get("graphFooter");
					if(graphHeader==null||graphHeader.length()==0)
					{
						//graphHeader=(String)chartObject.get("title");
						graphHeader=widgetHeader;
					}
					if(graphFooter==null||graphFooter.length()==0)
					{
						graphFooter=widgetFooter;
					}
				JSONObject gridObj=(JSONObject) chartCollecton.get(chartKey);
				if(gridObj!=null && gridObj.size()>0)
				{
					String title=(String) gridObj.get("title");
					if(title==null)
						title="";
					JSONArray gridData=(JSONArray) gridObj.get("gridData");
					Object gridColums_temp= gridObj.get("gridColums");
						////////// topn and table
						%>
						<div class="printOuterBox">
						<div class="printOuterBoxHeader"><%=graphHeader%></div>
						<%
					if(gridColums_temp instanceof JSONArray)
					{
						JSONArray gridColums=(JSONArray) gridObj.get("gridColums");
						System.out.println("instance of array");

%> 		
		<div class="newTable">
		<table align="center" cellspacing="0" cellpadding="0" width="97%"><col width="25%">
			<!--<tr>
					<td colspan="<%=gridColums.size() %>" class="printTableHeader" ><%=graphHeader%></td>
			</tr>-->
			<thead>
			<tr>
<%
		for(int tk=0;tk<gridColums.size();tk++)
		{
			String str=(String) gridColums.get(tk);	
			if(tk==0)
			{
%>
				<th align="left"><%=str %></th>
<%
			}
			else
			{
%>
				<th align="center"><%=str %></th>
<%
			}
		}
%>
			</tr>
			</thead>
			<tbody>
<%								
		String pattern = "(^[\"]?\\d+[\"]?$)|(^[\"]?\\d+(\\.\\d*)[\"]?$)"; 
		Pattern r = Pattern.compile(pattern);		
		for(int tk=0;tk<gridData.size();tk++)
		{
			JSONArray strArr=(JSONArray) gridData.get(tk);
			if(strArr!=null &&strArr.size()>0)
				{
%>
				<tr>			
<%	
						for(int jk=0;jk<strArr.size();jk++)
						{
							//String str=(String) strArr.get(jk);	
							String str=strArr.get(jk)+"";	
							Matcher m = r.matcher(str);
							if(m.find())
								str=utils.round(Double.parseDouble(str),4);
							//System.out.println("========str============>>>333333>>>>>>>>"+str);
							if(str.indexOf("~")>-1 && str.indexOf("~#~")==-1)
							{
								//System.out.println("========str====am comimg here also========>>>>>>>>>>>"+str);
								String valueAry[]=str.split("~");
								String barStr = "<table width='" + valueAry[2] + "' cellpadding='0' cellspacing='0' border='0'  height='8' class='prog_border'>";
								//barStr += "<tr>";
								//barStr += "<td align='left' width='100%' height='8' style='padding:0px'>";
								//barStr += "<table height='8'  cellpadding='0' cellspacing='0' border='0'>";
								barStr += "<tr>";
								barStr += "<td class='reporterProgressBar' width='" + valueAry[2] + "'  style='background:"+valueAry[1]+";padding:0px;height:8px'> </td>";
								barStr += "</tr>";
								//barStr += "</table>";
								//barStr += "</td>";
								//barStr += "</tr>";
								barStr += "</table>";
								str = "<table width='100%' cellpadding='0' cellspacing='0' border='0px'><tr><td style='padding:0px 20px 0px 0px;width:300px;border:0px' class='font_normal11'>" + valueAry[0] + "</td><td style='padding:0px;height:10px;border:0px'>" + barStr + "</td></tr></table>";
							}
							if(jk==0)
							{
%>
								<td align="left"><%=str %></td>
<%
							}
							else
							{
%>
								<td align="center"><%=str %></td>
<%
							}
						}									
%>
					</tr>			
<%	
					}
				}
%>
	<%
				if(graphFooter!=null && !graphFooter.equalsIgnoreCase("Notes"))
				{
	%>
						<tr>
							<td colspan="<%=gridColums.size() %>"  class="printTableHeader" width="100%" NOWRAP align="left">
								<table cellpadding="0px" cellspacing="0px" border="0px"><tr><td width="20px" style="padding:4px"><img src="/final/images/iconPrintDescription.png" /></td><td class="footer"><span class="<%=fontStyleDblSingl%>"><%=graphFooter%></span></td></tr></table>
							</td>
						</tr>
	<%
				}
	%>
				</tbody>
				</table>
			</div>
<%

		}
		else
		{
				System.out.println("instance of object");
			JSONObject gridColumsObj=(JSONObject) gridObj.get("gridColums");
			JSONArray dataAry=(JSONArray) gridData.get(0);
			ArrayList subColList = new ArrayList();
			Iterator iter = gridColumsObj.entrySet().iterator();
%> 		
			<div class="newTable">
			<table id="only-table" align="center" cellspacing="0" cellpadding="0" width="97%" class="gridTable"><col width="25%">
		
	<!--	<tr>
				<td colspan="<%=dataAry.size()%>" class="printTableHeader"  align="center" ><%=graphHeader%></td>
		</tr>-->
		<thead>
		<tr>
<%
		 while(iter.hasNext())
		{
			Map.Entry entryItr= (Map.Entry)iter.next();	
			String mainCol=(String)entryItr.getKey();
			JSONArray mainColAry = (JSONArray) gridColumsObj.get(mainCol);
			String settingInfo=" rowspan='2' ";
			if(mainColAry.size()>0)
			{
				settingInfo= " colspan='"+mainColAry.size()+"' ";
				for(int rv = 0;rv<mainColAry.size();rv++)
				{
					subColList.add(mainColAry.get(rv));
				}
			}
			%>
					<th <%=settingInfo%> class="printTableHeader" ><%=mainCol%></th>
			<%
		}
%>
		</tr>
<%
		if(subColList.size()>0)
		{
%>
		<tr>
<%
		for(int tk=0;tk<subColList.size();tk++)
		{
			String str=(String) subColList.get(tk);	
%>
			<th class="subHeader"><%=str %></th>
<%
		}
%>
		</tr>
		</thead>
		<tbody>
<%
		}		

%>
<%								
		for(int tk=0;tk<gridData.size();tk++)
		{
			JSONArray strArr=(JSONArray) gridData.get(tk);
			if(strArr!=null &&strArr.size()>0)
				{
%>
				<tr>			
<%	
						for(int jk=0;jk<strArr.size();jk++)
						{
								//String str=(String) strArr.get(jk);	
								String str=strArr.get(jk)+"";	
								if(str.indexOf(" week")>-1)
								{
									str=getDataForWeekGroup(str);
								}
								System.out.println("========str============>>>>>>>>>>>"+str);
								String strDecimal="";
								boolean isNumber = false;
								try{
									double f = Double.parseDouble(str);
									isNumber =true;
								}
								catch(Exception e)
								{
								}
								if(isNumber && str!=null && str.indexOf(".")>-1)
								{
									strDecimal = str.substring(str.indexOf("."));
									str = str.substring(0,str.indexOf("."));
%>
								<td><span class="decimal-align"><%=str %></span><span class="decimal-align2"><%=strDecimal %></span></td>
<%
								}
								else if(isNumber)
								{
%>
								<td><span class="decimal-align"><%=str %></td>
<%
								}
								else 
								{	
%>
						<td><%=str %></td>
<%
						}									
							}									
%>
					</tr>			
<%	
						}
					}
	%>
	<%
				if(graphFooter!=null && !graphFooter.equalsIgnoreCase("Notes"))
				{
	%>
						<tr>
							<td colspan="<%=dataAry.size() %>"  class="printTableHeader" width="100%" NOWRAP align="left">
								<table cellpadding="0px" cellspacing="0px" border="0px"><tr><td width="20px" style="padding:4px"><img src="/final/images/iconPrintDescription.png" /></td><td class="footer"><span class="<%=fontStyleDblSingl%>"><%=graphFooter%></span></td></tr></table>
							</td>
						</tr>
	<%
				}
%>
				</tbody>
				</table>
				</div>
			
<%

					}
					%>
					</div>
					<%
	
		}



			}
			else
			{
				sentQuery=	queryString+"&chartKey="+chartKey;
				System.out.println("queryStringqueryString="+sentQuery);
				String graphHeader = (String)chartObject.get("graphHeader");
				String graphFooter = (String)chartObject.get("graphFooter");
				String oneChartPerRow=null;
				if(chartObject.get("oneChartPerRow") != null)
				{
					oneChartPerRow = (String)chartObject.get("oneChartPerRow");
					strImgWidth="800";
					strGraphHeight="300";
				}
				if(graphHeader==null||graphHeader.length()==0)
				{
					graphHeader=(String)chartObject.get("title");
				}
				if(graphHeader==null||graphHeader.length()==0)
				{
					graphHeader=widgetHeader;
				}
				if(graphFooter==null||graphFooter.length()==0)
				{
					graphFooter=widgetFooter;
				}
			if(num==0 || (oneChartPerRow != null && oneChartPerRow.equals("true")))			
			{				
%>
					<tr>
<%				
			}			
%>				
						<td width="50%" style="padding:0px 10px 10px 0px">
							<div class="printOuterBox">
								<div class="printOuterBoxHeader"><%=graphHeader%></div>
								<div style="width:100%;overflow:auto;padding:10px"  align="center"><img src="<%=sentQuery%>&optt=graph&er_width=<%=strImgWidth%>&er_height=<%=strGraphHeight%>&er_view=IMAGE" border="0" hspace="0"  vspace="0" ></img></div>
	<%
								if(graphFooter!=null && !graphFooter.equalsIgnoreCase("Notes"))
								{
	%>
								<div class="printFooterText"><%=graphFooter%></div>
								
	<%
								}
	%>
						</div>
					</td>					
<%			if(num!=0 || (oneChartPerRow != null && oneChartPerRow.equals("true")))			
			{
				num=0;
%>
					</tr>
						<tr>
							<td colspan="2" width="100%" NOWRAP align="left">&nbsp;</td>
						</tr>
<%				
			}
				else
				num++;
				}
			
			}
			if(noOfCharts!=1&&noOfCharts%2==1)
			{
	%>
				<td></td></tr>
	<%
		}
			if(isGraph){
%>
				</table>
<%
				}
			}	
		}	
	}
	if(!dataAvailable)
	{
%>
				<table align="center" width="97%" cellspacing="0" cellpadding="4"   border="0">
					<tr>
						<table width='100%' height='100%'><tr>	<td align='center' valign='middle'><img src='../images/Light/nomeasures_custom.png' /></td></tr></table>
					</tr>
				</table>	
<%
	}
%>			
			 </br>
</body>
</html>

<%!

	public JSONObject prepareResultJsonforGrid(String chart_type,String widgetIdInfo,JSONObject sessionData,int graphIndex,String strUserDateFormat,String sessionCompName,User this_user)
	{
		ErUtils utils = new ErUtils(); 
		JSONObject returnJson = new JSONObject();
		SimpleDateFormat format=null;
		String pattern = "MM/dd/yyyy HH:mm:ss";	
		if(strUserDateFormat != null){
			strUserDateFormat=strUserDateFormat+" HH:mm:ss";
			format = new SimpleDateFormat(strUserDateFormat);
		}
		else
			format = new SimpleDateFormat(pattern);
		try
		{

			System.out.println("===sessionData======>>>..>>>>>>>>"+sessionData);
			JSONObject widgetDetailObj= new JSONObject();
			JSONArray tableArray=new JSONArray();
			JSONObject tableObj= new JSONObject();
			JSONArray gridCollectionArray=new JSONArray();
			JSONObject gridCollectionObj= new JSONObject();
			JSONObject selectionDetails= new JSONObject();
			JSONArray gridDataArry=new JSONArray();
			JSONArray gridCloumnArray=new JSONArray();
			String widgetHeader="";
			String widgetFooter="";
			String headerDescription="";
			List columnList=new ArrayList();//..

			
			
			if(sessionData!=null )
			{
				JSONObject widgetObj=(JSONObject)sessionData.get(widgetIdInfo);
				System.out.println("widgetObjwidgetObjwidgetObj   "+widgetObj);
				Iterator itr2 = widgetObj.entrySet().iterator();
				while(itr2.hasNext())
				{
					Map.Entry entry2= (Map.Entry)itr2.next();	
					String key=(String)entry2.getKey();
						
					if(key.equalsIgnoreCase("widgetHeader"))
					{
						widgetHeader=(String)entry2.getValue();
						System.out.println("widgetHeaderf= ghfh==>>>>>>  "+widgetHeader);
						continue;
					}
					else if(key.equalsIgnoreCase("widgetFooter"))
					{
						widgetFooter=(String)entry2.getValue();
						continue;
					}
					else if(key.equalsIgnoreCase("headerDescription"))
					{
						headerDescription=(String)entry2.getValue();
						continue;
					}
					else if(key.equalsIgnoreCase("widgetHeight"))
					{
						continue;
					}
					else if(key.equalsIgnoreCase("adjustWidgetHeight"))
					{
						continue;
					}
					else if(key.equalsIgnoreCase("widgetWidth"))
					{
						continue;
					}
					else if(key.equalsIgnoreCase("widgetPosition"))
					{
						continue;
					}
					else if(key.equalsIgnoreCase("widgetSize"))
					{
						continue;
					}
					else if(key.equalsIgnoreCase("DigitalChartCount") || key.equalsIgnoreCase("lineCls"))
					{
						continue;
					}
					else
					{
					chart_type=key;
					}
				}
				
				JSONArray timelineArray=(JSONArray)widgetObj.get(chart_type);
				String chartCollection="timelineChartCollection";
				if(chart_type.equals("bar") || chart_type.equals("vertbar"))
					chartCollection="barChartCollection";
				if(chart_type.equals("combinedChart"))
				{
					chartCollection="combinedChartCollection";
				}
				JSONArray timelineCollectionArray=null;
				if(sessionCompName!=null && sessionCompName.length()>0 && !sessionCompName.equalsIgnoreCase("null") && sessionCompName != "null")
				{
					timelineCollectionArray=(JSONArray)((JSONObject)((JSONObject)timelineArray.get(0)).get(chartCollection)).get(sessionCompName);
				}
				else
				{
					timelineCollectionArray=(JSONArray)((JSONObject)timelineArray.get(0)).get(chartCollection);
				}
				JSONObject timelineCollectionObj=(JSONObject)timelineCollectionArray.get(graphIndex);
				System.out.println("==timelineCollectionObj=====>sdfd>>>>>>>"+timelineCollectionObj);
				String title=(String)((JSONObject)timelineArray.get(0)).get("title");
				String tableTitle = (String)timelineCollectionObj.get("title");
				JSONArray timelineDataSet=(JSONArray)timelineCollectionObj.get("DataSet");
				String hasMonthOrWeekGroup=(String)timelineCollectionObj.get("hasMonthOrWeekGroup");
				
				EgTimeZoneConverter converterStart = null;
				if(hasMonthOrWeekGroup!=null && hasMonthOrWeekGroup.equalsIgnoreCase("yes"))
				{
					//..
					boolean threshStatus=false;
					for(int i=0;i<timelineDataSet.size();i++)
					{
						JSONObject timelineDataSetObj=(JSONObject)timelineDataSet.get(i);
						String name=(String)timelineDataSetObj.get("name");
						if(name != null && (name.indexOf("MIN") > -1 || name.indexOf("MAX") > -1))
							threshStatus=true;
					}
					//..
					if(threshStatus)
					{
						//gridCloumnArray.add("Components");
						gridCloumnArray.add("Date");
						//gridCloumnArray.add("Data");
						System.out.println("====datasetfirst===thresh=="+timelineDataSet);

						System.out.println("====datasetfirst====="+timelineDataSet);
						JSONObject timelineDataSetObj=(JSONObject)timelineDataSet.get(0);
						System.out.println("====sdfd====="+timelineDataSetObj);
						
						String name=(String)timelineDataSetObj.get("name");
						JSONArray dataAry=(JSONArray)timelineDataSetObj.get("data");					
						String threshVal=" ";
						gridCloumnArray.add(name);

						for(int i=0;i<timelineDataSet.size();i++)
						{
							JSONObject timelineDataSetObj1=(JSONObject)timelineDataSet.get(i);
							String name1=(String)timelineDataSetObj1.get("name");										
							//..for Threshold in header
							System.out.println("=======gridnmae=====>>>"+name1);
							if(name1 != null && (name1.indexOf("MIN") > -1 || name1.indexOf("MAX") > -1) && !columnList.contains(name1))
							{
								columnList.add(name1);
								gridCloumnArray.add(name1);
							}						
							
						}
						
						for(int j=0;j<dataAry.size();j++)
						{
							JSONArray dataValAry=(JSONArray)dataAry.get(j);
							JSONArray gridDataValArray = new JSONArray();
							//gridDataValArray.add(name);
							String date=dataValAry.get(0)+"";
							Date dateVal=new Date(Long.parseLong(date));
							gridDataValArray.add(format.format(dateVal).toString());
							gridDataValArray.add(utils.round(Double.parseDouble(dataValAry.get(1)+""),4));
							//......						
							for(int i=1;i<timelineDataSet.size();i++)
							{
								JSONObject timelineDataSetObjThresh=(JSONObject)timelineDataSet.get(i);
								JSONArray dataAryThresh=(JSONArray)timelineDataSetObjThresh.get("data");
								//System.out.println("=dataAryThresh=====>>>>>..>>>>>>>"+dataAryThresh);
								//for(int j=0;j<dataAry.size();j++)
								//{							
								if(j<dataAryThresh.size())
								{
									JSONArray dataValAryThresh=(JSONArray)dataAryThresh.get(j);
									threshVal=dataValAryThresh.get(1)+"";
									//gridDataValArray.add(dataValAryThresh.get(1)+"");
									//gridDataValArray.add(threshVal);
									gridDataValArray.add(utils.round(Double.parseDouble(threshVal),4));
								}
								else
								{
									//gridDataValArray.add(threshVal);
									gridDataValArray.add(utils.round(Double.parseDouble(threshVal),4));
								}
								
								//}
							}
							//......
							//System.out.println("=gridDataValArray========>>>>>>>>"+gridDataValArray);
							gridDataArry.add(gridDataValArray); 
						}
					}
					else
					{	
						//gridCloumnArray.add("Components");
						gridCloumnArray.add("Date");
						//gridCloumnArray.add("Data");
						JSONArray gridDataValArray=null;
						ArrayList entireDateList = new ArrayList();

						for(int i=0;i<timelineDataSet.size();i++)
						{
							JSONObject timelineDataSetObj=(JSONObject)timelineDataSet.get(i);
							String name=(String)timelineDataSetObj.get("name");
							JSONArray dataAry=(JSONArray)timelineDataSetObj.get("data");
							for(int j=0;j<dataAry.size();j++)
							{
								JSONArray dataValAry=(JSONArray)dataAry.get(j);
								String date = dataValAry.get(0)+"";
								if(!entireDateList.contains(date))
									entireDateList.add(date);
							}
						}
						Collections.sort(entireDateList);

						for(int i=0;i<timelineDataSet.size();i++)
						{
							JSONObject timelineDataSetObj=(JSONObject)timelineDataSet.get(i);
							String name=(String)timelineDataSetObj.get("name");
							gridCloumnArray.add(name);
							JSONArray dataAry=(JSONArray)timelineDataSetObj.get("data");
							for(int j=0;j<entireDateList.size();j++)
							{
								String date=(String)entireDateList.get(j);
								if(i==0)
								{
									gridDataValArray = new JSONArray();
									Date dateVal=new Date(Long.parseLong(date));
									String dateTemp = format.format(dateVal);
									converterStart = new EgTimeZoneConverter(dateTemp,this_user);
									dateTemp = converterStart.getDateTime();
									gridDataValArray.add(dateTemp);
								}
								else
									gridDataValArray = (JSONArray)gridDataArry.get(j);
								
								boolean isNotPresent=true;
								for(int k = 0; k<dataAry.size();k++)
								{
									JSONArray dataValAry=(JSONArray)dataAry.get(k);
									String cmpredate=dataValAry.get(0)+"";
									if(date.equalsIgnoreCase(cmpredate))
									{
										gridDataValArray.add(utils.round(Double.parseDouble(dataValAry.get(1)+""),4));
										isNotPresent=false;
										break;
									}	
								}
								if(isNotPresent)
									gridDataValArray.add("-");
								
								if(i==0)
									gridDataArry.add(gridDataValArray); 

							}
						}
					}
				}
				else
				{
					gridCloumnArray.add("Date/Time");
					JSONArray xAxisLabelAry=(JSONArray)timelineCollectionObj.get("xAxisLabel");
					
					gridDataArry = new JSONArray();
					JSONArray gridDataValArray=null;
					
					for(int i=0;i<timelineDataSet.size();i++)
					{
						JSONObject timelineDataSetObj=(JSONObject)timelineDataSet.get(i);
						String name=(String)timelineDataSetObj.get("name");
						gridCloumnArray.add(name);
						JSONArray dataAry=(JSONArray)timelineDataSetObj.get("data");
					
						for(int j=0;j<dataAry.size();j++)
						{
							if(dataAry.get(j) instanceof JSONArray)
							{
								JSONArray dataAryTemp = (JSONArray)dataAry.get(j);
								Long dateLong = (Long) dataAryTemp.get(0);
								Date dateVal = new Date(dateLong);
								String dateTemp = format.format(dateVal);
								converterStart = new EgTimeZoneConverter(dateTemp,this_user);
								dateTemp = converterStart.getDateTime();
								//
								if(i==0)
								{
									gridDataValArray = new JSONArray();
									gridDataValArray.add(dateTemp);
								}
								else
									gridDataValArray = (JSONArray)gridDataArry.get(j);
								
								gridDataValArray.add(dataAryTemp.get(1));
							}
							else
							{
								if(i==0)
								{
									gridDataValArray = new JSONArray();
									gridDataValArray.add((String)xAxisLabelAry.get(j));
								}
								else
									gridDataValArray = (JSONArray)gridDataArry.get(j);
							}
							if(i==0)
								gridDataArry.add(gridDataValArray);

							}
					}

				}

				gridCollectionObj.put("gridData",gridDataArry);
				gridCollectionObj.put("gridColums",gridCloumnArray);
				gridCollectionObj.put("title",title);

				gridCollectionArray.add(gridCollectionObj);
				if(sessionCompName!=null && sessionCompName.length()>0 && !sessionCompName.equalsIgnoreCase("null") && sessionCompName != "null")
				{
					JSONObject compAry = new JSONObject();
					compAry.put(sessionCompName,gridCollectionArray);
					tableObj.put("gridCollection",compAry);
				}
				else
				{
				tableObj.put("gridCollection",gridCollectionArray);
				}
				tableObj.put("title",title);
				tableArray.add(tableObj);
				widgetDetailObj.put("widgetHeader",widgetHeader);
				widgetDetailObj.put("widgetFooter",widgetFooter);
				widgetDetailObj.put("headerDescription",headerDescription);
				widgetDetailObj.put("table",tableArray);				
				returnJson.put("widget",widgetDetailObj);

			}
			System.out.println("[ErPrintReportBuilder.jsp] returnJson for Data grid "+returnJson);

			//returnJson=sessionData;
			
			}
			catch (Exception e)
			{
				e.printStackTrace(); 
			}

		return returnJson;
	}


	public JSONObject prepareResultJsonforGridNew(String chart_type,String widgetIdInfo,JSONObject sessionData,String graphIndex,String strUserDateFormat,String strShowBy,User this_user)
	{
		ErUtils utils = new ErUtils(); 
		JSONObject returnJson = new JSONObject();
		SimpleDateFormat format=null;
		String pattern = "MM/dd/yyyy HH:mm:ss";	
		if(strUserDateFormat != null){
			strUserDateFormat=strUserDateFormat+" HH:mm:ss";
			format = new SimpleDateFormat(strUserDateFormat);
		}
		else
			format = new SimpleDateFormat(pattern);
			//String dispDate = DateUtil.changeDateFormat(temp1,"MM/dd/yyyy",strUserDateFormat);
		EgTimeZoneConverter converterStart = null;
		try
		{

			JSONObject widgetDetailObj= new JSONObject();
			JSONArray tableArray=new JSONArray();
			JSONObject tableObj= new JSONObject();
			JSONArray gridCollectionArray=new JSONArray();
			String widgetHeader="";
			String widgetFooter="";
			String headerDescription="";
			//List columnList=new ArrayList();//..
			String title="";

			
			
			if(sessionData!=null )
			{
				JSONObject widgetObj=(JSONObject)sessionData.get(widgetIdInfo);
				Iterator itr2 = widgetObj.entrySet().iterator();
				while(itr2.hasNext())
				{
					Map.Entry entry2= (Map.Entry)itr2.next();	
					String key=(String)entry2.getKey();

					System.out.println("  key  "+key);
						
					if(key.equalsIgnoreCase("widgetHeader"))
					{
						widgetHeader=key;
						continue;
					}
					else if(key.equalsIgnoreCase("widgetFooter"))
					{
						widgetFooter=key;
						continue;
					}
					else if(key.equalsIgnoreCase("headerDescription"))
					{
						headerDescription=key;
						continue;
					}
					else if(key.equalsIgnoreCase("widgetHeight"))
					{
						//headerDescription=key;
						continue;
					}
					else if(key.equalsIgnoreCase("adjustWidgetHeight"))
					{
						//headerDescription=key;
						continue;
					}
					else if(key.equalsIgnoreCase("widgetWidth"))
					{
						//headerDescription=key;
						continue;
					}
					else if(key.equalsIgnoreCase("widgetPosition"))
					{
						//headerDescription=key;
						continue;
					}
					else if(key.equalsIgnoreCase("widgetSize"))
					{
						//headerDescription=key;
						continue;
					}
					else if(key.equalsIgnoreCase("DigitalChartCount") || key.equalsIgnoreCase("lineCls"))
					{
						//headerDescription=key;
						continue;
					}
					else
					{
					chart_type=key;
					}
				}
				
				JSONArray timelineArray=(JSONArray)widgetObj.get(chart_type);
				System.out.println("timelineArray=========="+timelineArray);
				String chartCollection="timelineChartCollection";
				if(chart_type.equals("bar") || chart_type.equals("vertbar"))
					chartCollection="barChartCollection";
				if(chart_type != null && chart_type.equalsIgnoreCase("combinedChart"))
				{
					chartCollection="combinedChartCollection";
				}
				JSONArray timelineCollectionArray=new JSONArray();
				System.out.println("===strShowBy===>>>>DFsd>>>>>>>>"+strShowBy);
				if(strShowBy!=null && strShowBy.equalsIgnoreCase("componentWise"))
				{
					JSONObject timelineCollectionArrayObj=(JSONObject)(((JSONObject)timelineArray.get(0)).get(chartCollection));	
					System.out.println("==timelineCollectionArrayObj===sdfds>SD>Fds>>>"+timelineCollectionArrayObj);
					Iterator keys = timelineCollectionArrayObj.keys();
					if( keys.hasNext() ){
					   String key = (String)keys.next(); // First key in your json object
					   timelineCollectionArray.add((JSONArray)timelineCollectionArrayObj.get(key));
					}
					System.out.println("===timelineCollectionArray===dfds==>>>"+timelineCollectionArray);
					timelineCollectionArray = (JSONArray)timelineCollectionArray.get(0);
				}
				else
				{
					timelineCollectionArray=(JSONArray)((JSONObject)timelineArray.get(0)).get(chartCollection);
				}
				if(timelineCollectionArray != null && timelineCollectionArray.size() > 0)
				{
					for(int ij=0;ij<timelineCollectionArray.size();ij++)
					{
						JSONObject gridCollectionObj= new JSONObject();//..
						JSONArray gridDataArry=new JSONArray();//..
						JSONArray gridCloumnArray=new JSONArray();//,..
						List columnList=new ArrayList();//..

						//JSONObject timelineCollectionObj=(JSONObject)timelineCollectionArray.get(graphIndex);
						JSONObject timelineCollectionObj=(JSONObject)timelineCollectionArray.get(ij);
						System.out.println("==timelineCollectionObj=====>sdfd>>>>>>>"+timelineCollectionObj);
					//	title=(String)((JSONObject)timelineArray.get(0)).get("title");
						title=(String)timelineCollectionObj.get("title");
						String tableTitle = (String)timelineCollectionObj.get("title");
						JSONArray timelineDataSet=(JSONArray)timelineCollectionObj.get("DataSet");
						String hasMonthOrWeekGroup=(String)timelineCollectionObj.get("hasMonthOrWeekGroup");
						System.out.println("====dataset>>>>====="+timelineDataSet);
						
						if(hasMonthOrWeekGroup!=null && hasMonthOrWeekGroup.equalsIgnoreCase("yes"))
						{
							//..
							boolean threshStatus=false;
							for(int i=0;i<timelineDataSet.size();i++)
							{
								JSONObject timelineDataSetObj=(JSONObject)timelineDataSet.get(i);
								String name=(String)timelineDataSetObj.get("name");
								if(name != null && (name.indexOf("MIN") > -1 || name.indexOf("MAX") > -1))
									threshStatus=true;
							}
							//..
							if(threshStatus)
							{
								//gridCloumnArray.add("Components");
								gridCloumnArray.add("Date");
								//gridCloumnArray.add("Data");
								System.out.println("====datasetfirst===thresh=="+timelineDataSet);

								System.out.println("====datasetfirst====="+timelineDataSet);
								JSONObject timelineDataSetObj=(JSONObject)timelineDataSet.get(0);
								System.out.println("====sdfd====="+timelineDataSetObj);
								
								String name=(String)timelineDataSetObj.get("name");
								JSONArray dataAry=(JSONArray)timelineDataSetObj.get("data");					
								String threshVal=" ";
								gridCloumnArray.add(name);

								for(int i=0;i<timelineDataSet.size();i++)
								{
									JSONObject timelineDataSetObj1=(JSONObject)timelineDataSet.get(i);
									String name1=(String)timelineDataSetObj1.get("name");										
									//..for Threshold in header
									System.out.println("=======gridnmae=====>>>"+name1);
									if(name1 != null && (name1.indexOf("MIN") > -1 || name1.indexOf("MAX") > -1) && !columnList.contains(name1))
									{
										columnList.add(name1);
										gridCloumnArray.add(name1);
									}						
									
								}
								
								for(int j=0;j<dataAry.size();j++)
								{
									JSONArray dataValAry=(JSONArray)dataAry.get(j);
									JSONArray gridDataValArray = new JSONArray();
									//gridDataValArray.add(name);
									String date=dataValAry.get(0)+"";
									Date dateVal=new Date(Long.parseLong(date));
									//
									String dateTemp = format.format(dateVal);
									converterStart = new EgTimeZoneConverter(dateTemp,this_user);
									dateTemp = converterStart.getDateTime();
									gridDataValArray.add(dateTemp);
									gridDataValArray.add(utils.round(Double.parseDouble(dataValAry.get(1)+""),4));
									//......						
									for(int i=1;i<timelineDataSet.size();i++)
									{
										JSONObject timelineDataSetObjThresh=(JSONObject)timelineDataSet.get(i);
										JSONArray dataAryThresh=(JSONArray)timelineDataSetObjThresh.get("data");						
										if(j<dataAryThresh.size())
										{
											JSONArray dataValAryThresh=(JSONArray)dataAryThresh.get(j);
											threshVal=dataValAryThresh.get(1)+"";
											gridDataValArray.add(utils.round(Double.parseDouble(threshVal),4));
										}
										else
										{
											gridDataValArray.add(utils.round(Double.parseDouble(threshVal),4));
										}
									}
									//......
									//System.out.println("=gridDataValArray========>>>>>>>>"+gridDataValArray);
									gridDataArry.add(gridDataValArray); 
								}
							}
							else
							{	
								//gridCloumnArray.add("Components");
								if(chart_type != null && chart_type.equals("bar"))
									gridCloumnArray.add("Components");//..
								else
									gridCloumnArray.add("Date");
								//gridCloumnArray.add("Data");
								JSONArray gridDataValArray=null;
								ArrayList entireDateList = new ArrayList();

								for(int i=0;i<timelineDataSet.size();i++)
								{
									JSONObject timelineDataSetObj=(JSONObject)timelineDataSet.get(i);
									String name=(String)timelineDataSetObj.get("name");
									JSONArray dataAry=(JSONArray)timelineDataSetObj.get("data");
									for(int j=0;j<dataAry.size();j++)
									{
										JSONArray dataValAry=(JSONArray)dataAry.get(j);
										String date = dataValAry.get(0)+"";
										if(!entireDateList.contains(date))
											entireDateList.add(date);
									}
								}
								Collections.sort(entireDateList);

								for(int i=0;i<timelineDataSet.size();i++)
								{
									JSONObject timelineDataSetObj=(JSONObject)timelineDataSet.get(i);
									String name=(String)timelineDataSetObj.get("name");
									gridCloumnArray.add(name);
									JSONArray dataAry=(JSONArray)timelineDataSetObj.get("data");
									for(int j=0;j<entireDateList.size();j++)
									{
										String date=(String)entireDateList.get(j);
										if(i==0)
										{
											gridDataValArray = new JSONArray();
											Date dateVal=new Date(Long.parseLong(date));
											//
											String dateTemp = format.format(dateVal);
											converterStart = new EgTimeZoneConverter(dateTemp,this_user);
											dateTemp = converterStart.getDateTime();
											gridDataValArray.add(dateTemp);
										}
										else
											gridDataValArray = (JSONArray)gridDataArry.get(j);
										
										boolean isNotPresent=true;
										for(int k = 0; k<dataAry.size();k++)
										{
											JSONArray dataValAry=(JSONArray)dataAry.get(k);
											String cmpredate=dataValAry.get(0)+"";
											if(date.equalsIgnoreCase(cmpredate))
											{
												gridDataValArray.add(utils.round(Double.parseDouble(dataValAry.get(1)+""),4));
												isNotPresent=false;
												break;
											}	
										}
										if(isNotPresent)
											gridDataValArray.add("-");
										
										if(i==0)
											gridDataArry.add(gridDataValArray); 

									}
								}
							}
						}
						else
						{
							gridCloumnArray.add("Date/Time");
							System.out.println("hasMonthOrWeekGrouphasMonthOrWeekGroup "+hasMonthOrWeekGroup);
							JSONArray xAxisLabelAry=(JSONArray)timelineCollectionObj.get("xAxisLabel");
							
							gridDataArry = new JSONArray();
							JSONArray gridDataValArray=null;
							
							for(int i=0;i<timelineDataSet.size();i++)
							{
								JSONObject timelineDataSetObj=(JSONObject)timelineDataSet.get(i);
								String name=(String)timelineDataSetObj.get("name");
								gridCloumnArray.add(name);
								JSONArray dataAry=(JSONArray)timelineDataSetObj.get("data");
							
								for(int j=0;j<dataAry.size();j++)
								{
									if(dataAry.get(j) instanceof JSONArray)
									{
										JSONArray eachAry = (JSONArray) dataAry.get(j);
										Long dateLong = (Long) eachAry.get(0);
										Date dateVal = new Date(dateLong);
										String date = format.format(dateVal);
										converterStart = new EgTimeZoneConverter(date,this_user);
										date = converterStart.getDateTime();
										if(i==0)
										{
											gridDataValArray = new JSONArray();
											gridDataValArray.add(date);
										}
										else
											gridDataValArray = (JSONArray)gridDataArry.get(j);
									}
									else
									{
										if(i==0)
										{
											gridDataValArray = new JSONArray();
											gridDataValArray.add((String)xAxisLabelAry.get(j));
										}
										else
											gridDataValArray = (JSONArray)gridDataArry.get(j);
									}
									
									if(chart_type.equals("bar"))
									{
										JSONObject barchartObj=(JSONObject)dataAry.get(j);
										gridDataValArray.add(utils.round(Double.parseDouble(barchartObj.get("y")+""),4));
									}
									else if(chart_type.equals("timeline"))
									{
										gridDataValArray.add(utils.round(Double.parseDouble(dataAry.get(j)+""),4));
									}
									else if(chart_type.equals("combinedChart"))
									{
										if(dataAry instanceof JSONArray)
										{
											JSONArray eachAry = (JSONArray) dataAry.get(j);
											gridDataValArray.add(utils.round(Double.parseDouble(eachAry.get(1)+""),4));
										}
										else
										{
											gridDataValArray.add(utils.round(Double.parseDouble(dataAry.get(j)+""),4));
										}
									}
									if(i==0)
										gridDataArry.add(gridDataValArray);

								}
							}

						}

						gridCollectionObj.put("gridData",gridDataArry);
						gridCollectionObj.put("gridColums",gridCloumnArray);
						gridCollectionObj.put("title",title);

						gridCollectionArray.add(gridCollectionObj);
					}
				}
				tableObj.put("gridCollection",gridCollectionArray);
				tableObj.put("title",title);
				tableArray.add(tableObj);
				widgetDetailObj.put("widgetHeader",widgetHeader);
				widgetDetailObj.put("widgetFooter",widgetFooter);
				widgetDetailObj.put("headerDescription",headerDescription);
				widgetDetailObj.put("table",tableArray);
				returnJson.put("widget",widgetDetailObj);

			}
			System.out.println("[ErPrintReportBuilder.jsp] returnJson  "+returnJson);

			//returnJson=sessionData;
			
			}
			catch (Exception e)
			{
				e.printStackTrace(); 
			}

		return returnJson;
	}

	public JSONObject prepareResultJsonPieToGrid(List selectedPieList,String distributedPieGroup,String range,String head,String foot,String widgetTitle)
	{
		JSONObject returnJson = new JSONObject();
		try
		{
			ErUtils utils = new ErUtils(); 
			JSONObject widgetDetailObj= new JSONObject();
			JSONArray tableArray=new JSONArray();
			JSONObject tableObj= new JSONObject();
			JSONArray gridCollectionArray=new JSONArray();
			JSONObject gridCollectionObj= new JSONObject();
			JSONArray gridDataArry=new JSONArray();
			JSONArray gridCloumnArray=new JSONArray();
			List keyList=new ArrayList();
			//StringTokenizer stl = new StringTokenizer(range, "-");
			ArrayList stl=ErUtils.egTokenizer(range, "-");
			String mapKey="",serverColumn="Server",tabelTitle="Tabel";
			
			double f_mn = Double.parseDouble(stl.get(0).toString().trim());
			double f_mx = Double.parseDouble(stl.get(1).toString().trim());
			
			if(distributedPieGroup!=null && distributedPieGroup.equalsIgnoreCase("none"))
			{
				serverColumn="Measure";
				for(int i=0;i<selectedPieList.size();i++)
				{
					List dbList = (ArrayList)selectedPieList.get(i);
					for(int j=0; j<dbList.size();j++)
					{
						Map mp=(Map) dbList.get(j);
						String serverName="";
						
						Iterator itr1 = mp.entrySet().iterator();
						while(itr1.hasNext())
						{
							Map.Entry entry1 = (Map.Entry)itr1.next();
							String key=(String)entry1.getKey();
							double dbData=Double.parseDouble((String)mp.get(key));
							dbData=Double.parseDouble(utils.round(Float.parseFloat(dbData+""),2));
							if(f_mx>= dbData && dbData >= f_mn)
							{
								tabelTitle=key.substring(0,key.indexOf("#$$"));
								serverName=key.substring(key.indexOf("#$$")+3,key.length());
								serverName = serverName.replaceAll("#"," - ");
								JSONArray gridDataValArray = new JSONArray();
								gridDataValArray.add(range);
								gridDataValArray.add(serverName);
								gridDataValArray.add(dbData+"");
								gridDataArry.add(gridDataValArray);
							}
						}
					}
				}
			
			}
			else
			{
				for(int i=0;i<selectedPieList.size();i++)
				{
					Map mp=(Map) selectedPieList.get(i);
					String serverName="";
					Iterator itr1 = mp.entrySet().iterator();
					while(itr1.hasNext())
					{
						Map.Entry entry1 = (Map.Entry)itr1.next();
						String key=(String)entry1.getKey();
						if(!keyList.contains(key))
							keyList.add(key);
					}

					if(distributedPieGroup.equalsIgnoreCase("single"))
					{
						mapKey=(String)keyList.get(1);
						serverName=(String)mp.get("trgt_host");
						if(serverName==null)
						{
							serverName=(String)mp.get("info"); 
							serverColumn="Descriptor";
						}
						if(serverName==null) //..for dd test
						{
							String ddCol=(String)keyList.get(0);
							serverName=(String)mp.get(ddCol);
						}
					}
					else if(distributedPieGroup.equalsIgnoreCase("both"))
					{
						serverColumn="Server/Descriptor";
						serverName=(String)mp.get("trgt_host")+" / "+(String)mp.get("info");
						mapKey=(String)keyList.get(2);
					}
					double dbData=Double.parseDouble((String)mp.get(mapKey));
					dbData=Double.parseDouble(utils.round(Float.parseFloat(dbData+""),2));
					if(f_mx>= dbData && dbData >= f_mn)
					{
						tabelTitle=mapKey.replace("#$$","-");
						tabelTitle=tabelTitle.replace("#","-");
						JSONArray gridDataValArray = new JSONArray();
						gridDataValArray.add(range);
						gridDataValArray.add(serverName);
						gridDataValArray.add(dbData+"");
						gridDataArry.add(gridDataValArray);
					}
				}
			}
			gridCloumnArray.add("Range");
			gridCloumnArray.add(serverColumn);
			gridCloumnArray.add("Data");


			gridCollectionObj.put("gridData",gridDataArry);
			gridCollectionObj.put("gridColums",gridCloumnArray);
			gridCollectionObj.put("title",tabelTitle);

			gridCollectionArray.add(gridCollectionObj);
			tableObj.put("gridCollection",gridCollectionArray);
			tableObj.put("title","Table");
			tableArray.add(tableObj);
			widgetDetailObj.put("table",tableArray);
			widgetDetailObj.put("widgetHeader",head);
			widgetDetailObj.put("widgetFooter",foot);
			widgetDetailObj.put("headerDescription",widgetTitle);
			returnJson.put("widget",widgetDetailObj);
		}
		catch (Exception e)
		{
			e.printStackTrace(); 
		}
		System.out.println("[ErPrintReportBuilder.jsp] pie returnJson  "+returnJson);

		return returnJson;
	}
	public String getDataForWeekGroup(String inVal)
	{
		String value=inVal;
		inVal=inVal.substring(0,inVal.indexOf("."));
		int intInVal = Integer.parseInt(inVal);
		switch(intInVal)
		{
			case 1:
				value=value.substring(value.indexOf(".")+1,value.length());
				value="Jan-"+value;
				break;
			case 2:
				value=value.substring(value.indexOf(".")+1,value.length());
				value="Feb-"+value;
				break;
			case 3:
				value=value.substring(value.indexOf(".")+1,value.length());
				value="Mar-"+value;
				break;
			case 4:
				value=value.substring(value.indexOf(".")+1,value.length());
				value="Apr-"+value;
				break;
			case 5:
				value=value.substring(value.indexOf(".")+1,value.length());
				value="May-"+value;
				break;
			case 6:
				value=value.substring(value.indexOf(".")+1,value.length());
				value="Jun-"+value;
				break;
			case 7:
				value=value.substring(value.indexOf(".")+1,value.length());
				value="Jul-"+value;
				break;
			case 8:
				value=value.substring(value.indexOf(".")+1,value.length());
				value="Aug-"+value;
				break;
			case 9:
				value=value.substring(value.indexOf(".")+1,value.length());
				value="Sep-"+value;
				break;
			case 10:
				value=value.substring(value.indexOf(".")+1,value.length());
				value="Oct-"+value;
				break;
			case 11:
				value=value.substring(value.indexOf(".")+1,value.length());
				value="Nov-"+value;
				break;
			case 12:
				value=value.substring(value.indexOf(".")+1,value.length());
				value="Dec-"+value;	
				break;			
		}
		return value;
	}
%>