首页 > 代码库 > chart.js操作实例(前后台互通)

chart.js操作实例(前后台互通)

前提:需要导入chart.js

            我的项目环境是:SpringMVC+mongodb

SpringMVC的controller层:

/**
	 * 查询得到财务信息报表
	 * @author liupeng
	 * @param request
	 * @return
	 * @throws UnknownHostException
	 * @throws ParseException 
	 */
	@RequestMapping(value=http://www.mamicode.com/"/innerChartOutForFinal")>
SpringMVC的DAO层:

/**
	 * 根据时间范围获取全部信息
	 * @author liupeng
	 * @param timeStart
	 * @param timeEnd
	 */
	public List<KeyRequest> findByTimeForFinalCommon(String timeStart, String timeEnd) {
		List<KeyRequest> kRList = new ArrayList<KeyRequest>();
		BasicDBObject obj = new BasicDBObject();
		obj.put("kq_timer_start",new BasicDBObject("$gte",timeStart).append("$lt", timeEnd));
		try{
			DBCursor dbCursor = keyRequest.find(obj).sort(new BasicDBObject("kq_timer_start",1));//以时间倒序排序,不排序的话数据会有问题,X坐标会显示相同的时间
			List<DBObject> list = dbCursor.toArray();
			for (DBObject dbObject:list) {
				KeyRequest tmp = setKeyRequest(dbObject);
				kRList.add(tmp);
			}
	
		}catch (Exception e) {
			e.printStackTrace();
		}
		return kRList;
	}



SpringMVC的显示层:

<%
		String strx = (String)request.getAttribute("strx");
		String strY1 = (String)request.getAttribute("strY1");
		String strY2 = (String)request.getAttribute("strY2");
		//"January","February","March","April","May","June","July"
	%>
	
	<script>  
    var data = http://www.mamicode.com/{>