echarts+java封装类实现图表的实例

作者:袖梨 2022-11-14

介绍了一个基于.net封装的echarts类,今天分享一下:echarts+java封装类实现图表的demo。

1、echarts封装类:

package com.ffcs.wlan.model;
import java.util.ArrayList;
import java.util.List;
public class EchartData {
public List legend = new ArrayList();//数据分组
public List category = new ArrayList();//横坐标
public List series = new ArrayList();//纵坐标
public EchartData(List legendList, List categoryList, List seriesList) {
super();
this.legend = legendList;
this.category = categoryList;
this.series = seriesList;
}
}

package com.ffcs.wlan.model;
import java.util.List;
public class Series {
public String name;
public String type;
public List data;//这里要用int 不能用String 不然前台显示不正常(特别是在做数学运算的时候)
public Series( String name, String type, List data) {
super();
this.name = name;
this.type = type;
this.data = data;
}
}

上面是Series 类。

2、控制器实现


package com.ffcs.wlan.controller;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ffcs.wlan.model.EchartData;
import com.ffcs.wlan.model.Series;
@Controller
@RequestMapping("/echarts")
public class EntityController {
private static final Logger logger = LoggerFactory.getLogger(EntityController.class);
@RequestMapping("/line_data")
@ResponseBody
public EchartData lineData() {
logger.info("lineData....");
List legend = new ArrayList(Arrays.asList(new String[]{"最高气温"}));//数据分组
List category = new ArrayList(Arrays.asList(new String []{"周一","周二","周三","周四","周五","周六","周日"}));//横坐标
List series = new ArrayList();//纵坐标
series.add(new Series("最高气温", "line",
new ArrayList(Arrays.asList(
21,23,28,26,21,33,44))));
EchartData data=new EchartData(legend, category, series);
return data;
}
@RequestMapping("/line_page")
public String linePage() {
logger.info("linePage....");
return "report/line";
}
}

3、jsp页面代码:

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>



line









注意路径${pageContext.request.contextPath}!

相关文章

精彩推荐