使用方法:
1、echart格式要求
"data":
{
"65#": [0.0, 0.0, 0.0, 0.0, 1865.61, 2434.85, 1818.32, 1618.36, 467.82, 429.13, 0.0, 0.0, 8634.08],
"66#": [0.0, 0.0, 0.0, 0.0, 40611.37, 49518.54, 54766.38, 61995.71, 48963.49, 43243.69, 0.0, 0.0, 299099.18],
"67#": [0.0, 0.0, 0.0, 0.0, 176266.25, 238119.63, 226450.61, 182006.53, 101416.06, 79829.52, 0.0, 0.0, 1004088.60],
"68#": [0.0, 0.0, 0.0, 0.0, 144978.69, 181543.25, 182163.81, 156560.42, 118934.34, 106977.26, 0.0, 0.0, 891157.77],
"69#": [0.0, 0.0, 0.0, 0.0, 14584.58, 26953.82, 27413.87, 18375.15, 19590.07, 19873.4, 0.0, 0.0, 126790.89]
},
"dataCost":
{
"65#": [0.0, 0.0, 0.0, 0.0, 1206.67, 1532.53, 1138.69, 966.92, 259.63, 238.04, 0.0, 0.0, 5342.48],
"66#": [0.0, 0.0, 0.0, 0.0, 28726.92, 34908.09, 37199.89, 40483.23, 32243.58, 27671.38, 0.0, 0.0, 201233.09],
"67#": [0.0, 0.0, 0.0, 0.0, 124669.4, 164303.48, 154700.65, 121408.76, 64808.9, 50572.82, 0.0, 0.0, 680464.01],
"68#": [0.0, 0.0, 0.0, 0.0, 98863.95, 122414.48, 122332.65, 100873.95, 77654.99, 71159.62, 0.0, 0.0, 593299.63],
"69#": [0.0, 0.0, 0.0, 0.0, 11466.93, 21150.41, 21155.81, 13705.31, 14826.01, 15017.97, 0.0, 0.0, 97322.44]
},
"datas": null,
"date": ["2018-02", "2018-03", "2018-04", "2018-05", "2018-06", "2018-07", "2018-08", "2018-09", "2018-10", "2018-11", "2018-12", "2019-01"],
"time": null,
"dataValue": null
2、转换为Echart图表格式数据
//res为list<map>集合
//成本
Map<String, Object> dataSubMap = new HashMap<String, Object>();
dataSubMap.put("data", "ArrayList");
Map<String, Object> dataMap = new HashMap<String, Object>();
dataMap.put("areaName", dataSubMap);
//用量
Map<String, Object> costSubMap = new HashMap<String, Object>();
costSubMap.put("cost", "ArrayList");
Map<String, Object> costMap = new HashMap<String, Object>();
costMap.put("areaName", costSubMap);
//转换
Map<String, Object> map = new HashMap<String, Object>();
map.put("unit", "tce");
map.put("date", "DISTINCT");
map.put("dataMap", dataMap);
map.put("costMap", costMap);
map.put("WithRateMap", WithRateMap);
map.put("ChainRateMap", ChainRateMap);
var ress = Convert.getEchartObject(res,map);
3、方法说明:
原理是根据echart格式样板仿一个map对象,转换方法根据map对象层数进行转换
map中key值用法
key值一般对应list<map>中字段值
1)、key值在存在于list<map>中key值时,取list<map>对应key的value值
2)、key值不存在于list<map>中key值时,取map的value值(例如:map.put("unit", "tce"), unit不存于List<map>中,返回结果就是value值“tce”)
map中value值用法
value值有三种用法
1)、作常量用,例如:map.put("unit", "tce") 中的 tce
2)、作关键字用,例如:map.put("date", "DISTINCT") 中的 DISTINCT
3)、作子map用,例如:map.put("dataMap", dataMap) 中的 dataMap
关键字:ArrayList、DISTINCT、List、Group(group为隐式关键字,value值为map时默认使用group分组),目前项目只需要用到这些,所以也只增加了这几种。
ArrayList 与 List的区别
ArrayList 取所有值做数组返回,key值为父级map的key值
例如:costSubMap.put("cost", "ArrayList");
List取所有值做数组,key值为当前map的key值
转换方法 CSDN 搜 java8 通用转echart方法