echarts图表ajax获取数据填充
发布日期:2021-06-30 16:29:06 浏览次数:2 分类:技术文章

本文共 3028 字,大约阅读时间需要 10 分钟。

js部分

/* ---------------- 折线图 ---------------   */		var line = echarts.init(document.getElementById('line'));//折线图	$.ajax({		    type: "post",		    url: '<%=basePath%>product.do?method=selectProductNum2',		    cache: false,		    dataType: "json",		    success: function(data) {		    			    			    	//------------定义折线图数据---------------				line.setOption({					color : [ "#32d2c9" ],					title : {						x : 'left',						text : '本年度新增产品统计',						textStyle : {							fontSize : '18',							color : '#4c4c4c',							fontWeight : 'bolder'						}					},					tooltip : {						trigger : 'axis'					},					toolbox : {						show : true,						feature : {							dataZoom : {								yAxisIndex : 'none'							},							dataView : {								readOnly : false							},							magicType : {								type : [ 'line', 'bar' ]							}						}					},					xAxis : {						type : 'category',						boundaryGap : false,						data : [ '一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月','九月' ,'十月' ,'十一月' ,'十二月'],						axisLabel : {							interval : 0						}					},					yAxis : {						type : 'value'					},					series : [ {						name : '平均',						type : 'line',						data : data,  //  这个地方填充获得的数据[ 23, 42, 18, 45, 48, 49, 100, 49, 100 ,49, 100, 49 ]						markLine : {							data : [ {								type : 'average',								name : '平均值'							} ]						}					} ]				});		    			    	//-----------------------------		    }	});
java后台代码

/**	 * 折线图表展示	 * @return	 */	@SuppressWarnings("deprecation")	public String selectProjectNum2(){		//得到今年的第一天		SimpleDateFormat dateFormat1 = new SimpleDateFormat("yyyy");		String format = dateFormat1.format(new Date());		SimpleDateFormat dateFormat2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");		String str = format+"-01-01 00:00:01";		Date parse = new Date();		try {			parse = dateFormat2.parse(str);		} catch (ParseException e2) {			e2.printStackTrace();		}		//得到今年的所有产品		List
findAll = projectService.findProjectAllByYear(parse.getTime()); int a=0,b=0,c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0; for (ProjectVO projectVO : findAll) { long createTime = projectVO.getCreateTime(); Date date = new Date(createTime); int month = date.getMonth()+1; switch (month) { case 1: a++; break; case 2: b++; break; case 3: c++; break; case 4: d++; break; case 5: e++; break; case 6: f++; break; case 7: g++; break; case 8: h++; break; case 9: i++; break; case 10: j++; break; case 11: k++; break; case 12: l++; break; default: break; } } List
months =new ArrayList
(0); months.add(a); months.add(b); months.add(c); months.add(d); months.add(e); months.add(f); months.add(g); months.add(h); months.add(i); months.add(j); months.add(k); months.add(l); JSONArray fromObject = JSONArray.fromObject(months); try { getResponse().setCharacterEncoding("utf-8"); getResponse().getWriter().write(fromObject.toString()); } catch (IOException e1) { e1.printStackTrace(); } return null; }

转载地址:https://kevin.blog.csdn.net/article/details/78734639 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:bootstrap模态框
下一篇:java正则工具类2

发表评论

最新留言

网站不错 人气很旺了 加油
[***.192.178.218]2024年04月20日 15时16分34秒