介绍了一个基于.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
public List
public List
public EchartData(List
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
public Series( String name, String type, List
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
List
List
series.add(new Series("最高气温", "line",
new ArrayList
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"%>
注意路径${pageContext.request.contextPath}!