• JSON, list, 前台显示


    前台

    $(function(){
    			$.getJSON("/portal/visitor/getVisitorCount?rn="+Math.random(),function(jsondata){
    			document.getElementById("todaytotal").innerText=jsondata[0].total[29];
    			var data = [
    						{
    							name : 'SW Group',
    							value:jsondata[0].swCount,
    							color:'#cbab4f',
    							line_2
    						},
    			         	{
    			         		name : 'System S/W R&D 1Part',
    			         		value:jsondata[0].sw1Count,
    			         		color:'#a5c2d5',
    			         		line_2
    			         	},
    			         	
    			         	{
    			         		name : 'System S/W R&D 2Part',
    			         		value:jsondata[0].sw2Count,
    			         		color:'#76a871',
    			         		line_2
    			         	},
    			         	{
    			         		name : 'Mon(S)开发Part',
    			         		value:jsondata[0].monCount,
    			         		color:'#9f7961',
    			         		line_2
    			         	},
    			         	{
    			         		name : 'SE',
    			         		value:jsondata[0].seCount,
    			         		color:'#a56f8f',
    			         		line_2
    			         	},{
    			         		name : 'SQA&Other',
    			         		value:jsondata[0].sqaCount,
    			         		color:'#6f83a5',
    			         		line_2
    			         	},{
    			         		name : 'Total',
    			         		value:jsondata[0].total,
    			         		color:'#CC0000',
    			         		line_2
    			         	}
    			         ];
    	         
    			var labels = ["",""+(time(-28).getMonth()+1)+"/"+time(-28).getDate()+"","",""+(time(-26).getMonth()+1)+"/"+time(-26).getDate()+"","",""+(time(-24).getMonth()+1)+"/"+time(-24).getDate()+"","",""+(time(-22).getMonth()+1)+"/"+time(-22).getDate()+"","",""+(time(-20).getMonth()+1)+"/"+time(-20).getDate()+"","",""+(time(-18).getMonth()+1)+"/"+time(-18).getDate()+"","",""+(time(-16).getMonth()+1)+"/"+time(-16).getDate()+"","",""+(time(-14).getMonth()+1)+"/"+time(-14).getDate()+"","",""+(time(-12).getMonth()+1)+"/"+time(-12).getDate()+"","",""+(time(-10).getMonth()+1)+"/"+time(-10).getDate()+"","",""+(time(-8).getMonth()+1)+"/"+time(-8).getDate()+"","",""+(time(-6).getMonth()+1)+"/"+time(-6).getDate()+"","",""+(time(-4).getMonth()+1)+"/"+time(-4).getDate()+"","",""+(time(-2).getMonth()+1)+"/"+time(-2).getDate()+"","",""+(time(0).getMonth()+1)+"/"+time(0).getDate()+""];
    			var line = new iChart.LineBasic2D({
    				render : 'canvasDiv',
    				data: data,
    				align:'center',
    				//title : 'SW Portal Recent 30D Flow Analysis',
    				title : {
    					text:'Access Record',
    					fontsize:11,
    					color:'#000000'
    				},
    
    				width : 1500,
    				height : 320,
    				background_color : '#FFFFFF',
    				tip:{
    					enable :true,
    					shadow:true,
    					listeners:{  
    						//tip:提示框对象、name:数据名称、value:数据值、text:当前文本、i:数据点的索引
    						parseText:function(tip,name,value,text,i){
    							return name+" : "+value;
    						}
    					} 
    				},
    				legend : {
    					enable : true,
    					row:1,//设置在一行上显示,与column配合使用
    					column : 'max',
    					valign:'top',
    					sign:'round',
    					fontsize:10,
    					background_color:null,//设置透明背景
    					offsetx:-220,//设置x轴偏移,满足位置需要
    					offsety:-5,//设置x轴偏移,满足位置需要
    					border : true
    				},
    				crosshair:{
    					enable:true,
    					line_color:'#62bce9'
    				},
    				sub_option : {
    					border:{
    						enable:false
    					},
    					
    					label:false,
    					point_hollow : false
    				},
    				border:{
    					color:'#ffffff'
    				},  //去掉外边框
    				coordinate:{
    					1050,
    					height:200,
    					axis:{
    						color:'#9f9f9f',
    						[0,0,1,1]
    					},
    					grids:{
    						
    					},
    					scale:[{
    						position:'left',	
    						scale_enable : true,
    						start_scale:0,
    						scale_space:5,
    						end_scale:10,
    						label : {color:'#000000',fontsize:11} //竖轴文字样式
    					},{
    						 position:'bottom',	
    						 label : {color:'#000000',fontsize:11},//横轴文字样式
    						 labels:labels,
    					}]
    				}
    			});
    		
    		//开始画图
    		line.draw();
    			});
    	});
    

     后台controller

    @RequestMapping("/getVisitorCount")
    	@ResponseBody
    	public void getVisitorCount(HttpServletRequest request,HttpServletResponse response){
    		Date date=new Date();//取时间  
    		Calendar calendar = new GregorianCalendar();  
    		calendar.setTime(date);  
    		calendar.add(calendar.DATE,-29);//把日期往后增加一天.整数往后推,负数往前移动  
    		date=calendar.getTime(); //这个时间就是日期往后推一天的结果   
    		SimpleDateFormat formatter = new SimpleDateFormat("yyyy/MM/dd"); 
    		String[] curdate = new String[30];
    		curdate[0]=formatter.format(calendar.getTime());
    		for(int i = 1 ;i<30;i++){
    			calendar.add(calendar.DATE,+1);//把日期往后增加一天.整数往后推,负数往前移动  
    			curdate[i] =formatter.format(calendar.getTime());
    		}
    		
    		List<Long> sw1Count = new ArrayList<Long>();
    		List<Long> sw2Count = new ArrayList<Long>();
    		List<Long> swCount = new ArrayList<Long>();
    		List<Long> seCount = new ArrayList<Long>();
    		List<Long> monCount = new ArrayList<Long>();
    		List<Long> sqaCount = new ArrayList<Long>();
    		List<Long> total = new ArrayList<Long>();
    		
    		for(int i=0;i<30;i++){
    			sw1Count.add(visitorService.getSW1Count(curdate[i]));
    			sw2Count.add(visitorService.getSW2Count(curdate[i]));
    			swCount.add(visitorService.getSWCount(curdate[i]));
    			seCount.add(visitorService.getSECount(curdate[i]));
    			monCount.add(visitorService.getMONCount(curdate[i]));
    			sqaCount.add(visitorService.getSQACount(curdate[i]));
    			total.add(visitorService.getSW1Count(curdate[i])+visitorService.getSW2Count(curdate[i])+visitorService.getSWCount(curdate[i])+visitorService.getSECount(curdate[i])+visitorService.getMONCount(curdate[i])+visitorService.getSQACount(curdate[i]));
    		}
    		
    
        	//request.getSession().setAttribute("eduTotal", categoryTotal);
    		response.reset();
    	    response.setCharacterEncoding("UTF-8");
    	    //response.setContentType("application/json;charset=utf-8");
    	    response.setContentType("text/html");
    	     
    	    JSONArray members = new JSONArray();
    	    PrintWriter out= null;
    	    try {
    	    		out= response.getWriter();
    	            JSONObject member = new JSONObject();
    	            member.put("sw1Count", sw1Count);
    	            member.put("sw2Count", sw2Count);
    	            member.put("swCount", swCount);
    	            member.put("seCount", seCount);
    	            member.put("monCount", monCount);
    	            member.put("sqaCount", sqaCount);
    	            member.put("total", total);
    	            members.add(member);               
    	            out.write(members.toString());
    	         
    	    } catch (Exception e) {
    	        System.out.println(e.getMessage());
    	        out.flush();
    	        out.close();    
    	    }      
    	 
    	    out.flush();
    	    out.close();  
    	}
    

    数据库获取数据

    @Override
    	public Long getSW2Count(String curdate) {
    		List<Visitor> list = getSession().createQuery("FROM Visitor v WHERE  v.part like '%System S/W R&D 2Part%' AND v.visitDate like '%"+curdate+"%'").list();
    		Long sw2Count = Long.valueOf(list.size());
    		return sw2Count;
    	}
    
  • 相关阅读:
    21. 斐波那契数列
    22. 旋转数组的最小数字
    php图像处理链接
    FileOprSer.class.php(文件上传与下载类)
    SqlHelper.class.php+分页类方法
    file写入方式 和copy
    file 读取方式
    pytest+allure+jenkins 持续集成平台生成allure报告
    memcached cas操作
    php-fpm
  • 原文地址:https://www.cnblogs.com/wujixing/p/6006767.html
Copyright © 2020-2023  润新知