java统一封装E-chat图形返回数据结构
程序员文章站
2022-03-22 19:55:52
...
直接上代码,封装需要用到的实体类
/**
* Mr peng
* 2020-08-04 17:30:03
* 统计图返回结构
*/
public class StatisticalDataEntity implements Serializable {
private static final long serialVersionUID = -3972286994024019236L;
private String name; //标题名
private String width; //12代表一行两个图,24代表一个
private String chartType; //bar代表柱状图,line代表线状图,pie代表圆形图
private Chart data; //存放表头和表值
private String sumNumber; //总数量
public String getSumNumber() {
return sumNumber;
}
public void setSumNumber(String sumNumber) {
this.sumNumber = sumNumber;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getWidth() {
return width;
}
public void setWidth(String width) {
this.width = width;
}
public String getChartType() {
return chartType;
}
public void setChartType(String chartType) {
this.chartType = chartType;
}
public Chart getData() {
return data;
}
public void setData(Chart data) {
this.data = data;
}
}
public class Chart<T> {
private List<String> xAxis; //表头
private List<Series<T>> series; //数据
public List<String> getxAxis() {
return xAxis;
}
public void setxAxis(List<String> xAxis) {
this.xAxis = xAxis;
}
public List<Series<T>> getSeries() {
return series;
}
public void setSeries(List<Series<T>> series) {
this.series = series;
}
}
public class Series<T> {
private String name; //当前图名
private List<T> data; //数据
private String stack;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public List<T> getData() {
return data;
}
public void setData(List<T> data) {
this.data = data;
}
public String getStack() {
return stack;
}
public void setStack(String stack) {
this.stack = stack;
}
}
直接上代码,封装一个图表的通用方法
/**
* Mr peng 2020-08-04 12:03
* @param xAxisList 图字段
* @param seriesData 图数据
* @param title 标题名
* @param type bar=柱状图,line-线状图,pie-圆形图
* @param width 24表一张图,12表示两张图
* @param name 图表名
* @param sumNumber //总数量
* @return
*/
public StatisticalDataEntity getChartInfo(List<String> xAxisList, List<String> seriesData, String title, String type, String width, String name, Integer sumNumber){
StatisticalDataEntity sde = new StatisticalDataEntity();
Chart char1= new Chart();
List<String> xAxis = xAxisList;
List<Series> seriesList = new ArrayList<Series>();
Series series = new Series();
series.setData(seriesData);
series.setName(title);
seriesList.add(series);
char1.setxAxis(xAxis);
char1.setSeries(seriesList);
sde.setName(name);
sde.setData(char1);
sde.setWidth(width);
sde.setChartType(type);
sde.setSumNumber(sumNumber.toString());
return sde;
}
上一篇: 大话数据结构---双向链表的插入与删除