【Echarts】Echarts2.0动态加载扇形图。

Echarts在数据可视化方面广泛使用,记录一个使用Echarts动态加载扇形图的例子。方便以后使用。

【Echarts】2.0官方API:http://echarts.baidu.com/echarts2/doc/example.html

【Echarts】3.0官方API:http://echarts.baidu.com


HTML代码:


    社会治理
	
    	
    	
    	
    
   	 

	
	
  	
	
	
	
	
		


controller代码:

@ResponseBody
	@RequestMapping(value="/getGovernanceforDriver")
	public Map getGovernanceforDriver(){
		logger.info("333");
		Map data = service.getGovernanceforDriver();
		return data;
	}

service层代码:

public Map getGovernanceforDriver(){
		List governances = dao.getGovernance();
		Map data = new HashMap();
		List legendArr = new ArrayList();
		List valueArr = new ArrayList();
		if(governances.size()>0){
			List governanceforDrivers = new ArrayList();
			for(Governance governance:governances){
				GovernanceforDriver governanceforDriver = new GovernanceforDriver();
				governanceforDriver.setCommunityName(governance.getCommunityName());
				governanceforDriver.setCommunityId(governance.getCommunityId());
				governanceforDrivers.add(governanceforDriver);
				legendArr.add(governanceforDriver.getCommunityName());
				valueArr.add(governanceforDriver.getCommunityId());
			}
			data.put("legendArr", legendArr);
			data.put("valueArr",valueArr);
		}else{
			data.put("legendArr", null);
			data.put("valueArr",null);
		}
		return data;
	} 
  

效果图:

【Echarts】Echarts2.0动态加载扇形图。_第1张图片


仅此记录,以防忘记。



你可能感兴趣的:(java开发,前端相关)