您的位置:首页 > 其它

echarts处理查询数据总结

2016-12-27 16:46 183 查看
package com.jiupaicn.wuhan.tools;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;

import org.codehaus.jackson.JsonGenerationException;
import org.codehaus.jackson.map.JsonMappingException;

/**
* echarts 图表的几个方法
* @author zengpan
*
*/
public class Echarts {

/**
* 获取饼图信息
* @param statMap 饼图数据信息 key:名称 ,value:数值
* @param title 饼图名称
* @return  图形json格式信息
* @throws IOException
* @throws JsonMappingException
* @throws JsonGenerationException
*/
public Map<String, Object> getPieData(Map<String, Integer> statMap,String title) throws JsonGenerationException, JsonMappingException, IOException {
Map<String, Object> resultMap = new HashMap<String, Object>();//定义存放饼图信息的map集合
List<String> legendList = new ArrayList<String>();//定义存放图例的list集合
StringBuffer info = new StringBuffer();
if(statMap.size()!=0&&statMap!=null) {
int i = 0;
info.append("[");
for(Map.Entry<String, Integer> entry : statMap.entrySet()) {
i++;
info.append("{value:");
info.append(entry.getValue());
info.append(",name:'");
info.append(entry.getKey());
if(i!=statMap.size()){
info.append("'},");
}else {
info.append("'}");
}
legendList.add(entry.getKey());
}
info.append("]");
}
resultMap.put("title", title);
resultMap.put("legend", legendList);//图例
resultMap.put("num",info.toString());//获取饼图数据信息( series:data信息)
//JSONObject json = JSONObject.fromObject(resultMap);
//ObjectMapper objectMapper = new ObjectMapper();
//String json = objectMapper.writeValueAsString(resultMap);
//return json;
return resultMap;
}

/**
*  获取折线图or普通柱状图数据(x轴为时间)
* @param map key:每条折线(柱状)的名称 value:值也是一map集合(key:日期,value:数值)
* @param format1 传入的时间格式
* @param format2 折线图x轴的时间格式
* @param startDate 起始日期
* @param endDate 终止日期
* @param title 图形标题
* @param type 1:折线图 2:柱状图
* @return 图形json格式信息
*/
public Map<String, Object> getLineOrColumnData(Map<String, Map<String, Integer>> map,String format1,String format2,String startDate,String endDate,String title,int type) {
Map<String, Object> resultMap = new HashMap<String, Object>();//定义存放图形信息的map集合
List<String> legendList = new ArrayList<String>();//定义存放图例的list集合
List<String> dateList = new ArrayList<String>(); //定义存放日期的list集合
TimeFormat timeFormat = TimeFormat.getInstance();
Map<String, Object> mapkeydate = new LinkedHashMap<String, Object>();//定义存放日期map集合 key:日期; value:0
int days = timeFormat.getCalDateDiff(format1, startDate, endDate, 1);
for(int i = days;i>=0;--i) { //得到指定范围的时间
String date = timeFormat.getDate("yyyyMMdd", format1, endDate,i>0?-i:0);
mapkeydate.put(date,0);
String date_list = timeFormat.getDate(format2, format1, endDate,i>0?-i:0);
dateList.add(date_list);
}
StringBuffer info = new StringBuffer();
if(map!=null && map.size()!=0) {
int i = 0;
info.append("[");
for(Entry<String, Map<String, Integer>> entry : map.entrySet()) {//1-- for start
i++;
legendList.add(entry.getKey());//图例
info.append("{name:'");
info.append(entry.getKey());
info.append("',");
info.append("type:'");
if(type==1) {
info.append("line");
}else if(type==2) {
info.append("bar");
}
info.append("',");
info.append("data:[");
Map<String, Integer>map2 = (Map<String, Integer>) entry.getValue();
int j=0;
for(Entry<String, Object> entry2:mapkeydate.entrySet()){  //2-- for start
j++;
if(map2.get(entry2.getKey())==null) {
info.append(0);
}else {
info.append(map2.get(entry2.getKey()));
}
if (j!=mapkeydate.size()) {
info.append(",");
}else {
info.append("]");
}
}//2-- for end
if(i!=map.size()){
info.append("},");
}else {
info.append("}");
}
}//1--for end
info.append("]");
}
resultMap.put("title", title);
resultMap.put("legend", legendList);//图例
resultMap.put("date", dateList);//日期
resultMap.put("num",info.toString());//获取图形数据信息( series:data信息)

return resultMap;
}

/**
*  获取堆积柱状图数据
* @param map key:每个柱的名称 value:值也是一map集合(key:日期,value:数值)
* @param map_x x轴信息map集合
* @param title 图形标题
* @return 图形json格式信息
* @throws IOException
* @throws JsonMappingException
* @throws JsonGenerationException
*/
public Map<String, Object> getAccumulateColumnData(Map<String, Map<String, Integer>> map,Map<String, Object> map_x,String title) throws JsonGenerationException, JsonMappingException, IOException {
Map<String, Object> resultMap = new HashMap<String, Object>();//定义存放图形信息的map集合
List<String> legendList = new ArrayList<String>();//定义存放图例的list集合
List<String> x_List = new ArrayList<String>(); //定义存放x轴的list集合
StringBuffer info = new StringBuffer();
if(map.size()!=0&&map!=null) {
int i = 0;
info.append("[");
for(Entry<String, Map<String, Integer>> entry : map.entrySet()) {//1-- for start
i++;
legendList.add(entry.getKey());//图例
info.append("{name:'");
info.append(entry.getKey());
info.append("',");
info.append("type:'bar',");
info.append("stack: '总量',");
info.append("itemStyle : { normal: {label : {show: true, position: 'insideRight'}}},");
info.append("data:[");
Map<String, Integer> map2 = (Map<String, Integer>) entry.getValue();
int j=0;
for(Entry<String, Object> entry2:map_x.entrySet()){  //2-- for start
j++;
if(i==1) x_List.add(entry2.getKey());
if(map2.get(entry2.getKey())==null) {
info.append(0);
}else {
info.append(map2.get(entry2.getKey()));
}
if (j!=map_x.size()) {
info.append(",");
}else {
info.append("]");
}
}//2-- for end
if(i!=map.size()){
info.append("},");
}else {
info.append("}");
}
}//1--for end
info.append("]");
}
resultMap.put("title", title);
resultMap.put("legend", legendList);//图例
resultMap.put("x_data", x_List);//x轴信息
resultMap.put("num",info.toString());//获取图形数据信息( series:data信息)
//JSONObject json = JSONObject.fromObject(resultMap);
//ObjectMapper objectMapper = new ObjectMapper();
//String json = objectMapper.writeValueAsString(resultMap);
//return json;
return resultMap;
}

/**
*  获取横向(纵向)普通柱状图数据(无分组x或 y轴非时间))
* @param map key:每个柱的名称 value:数值
* @param title 图形标题
* @param type 1:横向 2:纵向
* @return 图形json格式信息
* @throws IOException
* @throws JsonMappingException
* @throws JsonGenerationException
*/
public Map<String, Object> getLevelColumnChartData(Map<String, Integer> map,String title,int type) throws JsonGenerationException, JsonMappingException, IOException {
Map<String, Object> resultMap = new HashMap<String, Object>();//定义存放图形信息的map集合
List<String> y_List = new ArrayList<String>(); //定义存放y轴的list集合
StringBuffer info = new StringBuffer();
if(map.size()!=0&&map!=null) {
info.append("[");
info.append("{");
info.append("type:'bar',");
info.append("radius : '85%',");
info.append("itemStyle : { normal: {label : {show: true, position: ");
if(type==1) {
info.append("'insideRight'}}},");
}else if(type==2) {
info.append("'top'}}},");
}
info.append("data:[");

//将Map转化为List集合,List采用ArrayList
List<Map.Entry<String, Integer>> list_Data = new ArrayList<Map.Entry<String,Integer>>(map.entrySet());
//通过Collections.sort(List I,Comparator c)方法进行排序
//          Collections.sort(list_Data,new Comparator<Map.Entry<String, Integer>>() {
//
//              public int compare(Entry<String, Integer> o1, Entry<String, Integer> o2) {
//                  return (o1.getValue() - o2.getValue());
//              }
//          });

for(int i=0; i<list_Data.size(); i++){
y_List.add(list_Data.get(i).getKey());
info.append(map.get(list_Data.get(i).getKey()));
if (i < map.size() -1) {
info.append(",");
}else {
info.append("]");
}
}
/*  int i=0;
for(Entry<String, Integer> entry:map.entrySet()){
i++;
y_List.add(entry.getKey());
info.append(map.get(entry.getKey()));
if (i!=map.size()) {
info.append(",");
}else {
info.append("]");
}
}*/
info.append("}");
info.append("]");
}
resultMap.put("title", title);
resultMap.put("y_data", y_List);//y轴信息
resultMap.put("num",info.toString());//获取图形数据信息( series:data信息)
//JSONObject json = JSONObject.fromObject(resultMap);
//ObjectMapper objectMapper = new ObjectMapper();
//String json = objectMapper.writeValueAsString(resultMap);
//return json;
return resultMap;
}

/**
* 地图Echarts
* @param map
* @param title
* @param box
* @return
* @throws IOException
* @throws JsonMappingException
* @throws JsonGenerationException
*/
public Map<String, Object> getWuHanMap(Map<String, Integer> map,String title, boolean box, String cityName) throws JsonGenerationException, JsonMappingException, IOException{
Map<String, Object> resultMap = new HashMap<String, Object>();//定义存放图形信息的map集合
StringBuffer info = new StringBuffer();
int max = 0;
if(map != null){
int i=0;

info.append("[");
for (String str : map.keySet()) {
info.append("{");
info.append("name:");
info.append("'"+ str +"'");
info.append(",value:"+ map.get(str));
if(str.equals(cityName)){   //地区高亮
info.append(",selected:true");
}
info.append("}");
if(i < (map.size()-1)){
info.append(",");
}
i++;
if(map.get(str) > max){
max = map.get(str);
}
}
info.append("]");
}

resultMap.put("title", title);
resultMap.put("box", box);
resultMap.put("num", info.toString());
resultMap.put("max", max);
//JSONObject json = JSONObject.fromObject(resultMap);
//ObjectMapper objectMapper = new ObjectMapper();
//String json = objectMapper.writeValueAsString(resultMap);
//return json;
return resultMap;
}

/**
* 地图Echarts
* @param map
* @param title
* @param box
* @return
* @throws IOException
* @throws JsonMappingException
* @throws JsonGenerationException
*/
public Map<String, Object> getChianMap(Map<String, Integer> map,String title, boolean box, String cityName) throws JsonGenerationException, JsonMappingException, IOException{
Map<String, Object> resultMap = new HashMap<String, Object>();//定义存放图形信息的map集合
StringBuffer info = new StringBuffer();
int max = 0;
if(map != null){
int i=0;

info.append("[");
for (String str : map.keySet()) {
info.append("{");
info.append("name:");
String str1=str.replaceAll("市", "").replaceAll("省", "").replaceAll("维吾尔自治区", "").replaceAll("自治区", "").replaceAll("壮族自治区", "").replaceAll("回族自治区", "");
info.append("'"+ str1 +"'");

info.append(",value:"+ map.get(str));
if(str.equals(cityName)){   //地区高亮
info.append(",selected:true");
}
info.append("}");
if(i < (map.size()-1)){
info.append(",");
}
i++;
if(map.get(str) > max){
max = map.get(str);
}
}
info.append("]");
}

resultMap.put("title", title);
resultMap.put("box", box);
resultMap.put("num", info.toString());
resultMap.put("max", max);
//JSONObject json = JSONObject.fromObject(resultMap);
//ObjectMapper objectMapper = new ObjectMapper();
//String json = objectMapper.writeValueAsString(resultMap);
//return json;
return resultMap;
}

public Map<String, Object> getProvinceData(Map<String, Map<String, Integer>> map,String title, int type) throws JsonGenerationException, JsonMappingException, IOException {
Map<String, Object> resultMap = new HashMap<String, Object>();//定义存放图形信息的map集合
List<String> legendList = new ArrayList<String>();//定义存放图例的list集合
List<String> dateList = new ArrayList<String>(); //定义存放日期的list集合

Map<String, Integer>map3 = new HashMap<String, Integer>();
//Map<String, Object> mapkeydate = new LinkedHashMap<String, Object>();//定义存放日期map集合 key:日期; value:0
//2-- for end
StringBuffer info = new StringBuffer();
if(map!=null && map.size()!=0) {
int i = 0;
info.append("[");
for(Entry<String, Map<String, Integer>> entry : map.entrySet()) {//1-- for start
i++;
legendList.add(entry.getKey());//图例
info.append("{name:'");
info.append(entry.getKey());
info.append("',");
info.append("type:'");
info.append("bar");

info.append("',");

if(type == 1){
/*info.append("itemStyle: {normal: {color: function(params) {var colorList = " +
"['#C1232B','#C1232B','#C1232B','#C1232B','#C1232B','#C1232B','#C1232B'," +
"'#C1232B','#C1232B','#C1232B','#C1232B','#C1232B','#C1232B','#C1232B'," +
"'#C1232B','#C1232B','#C1232B','#C1232B','#C1232B','#C1232B','#C1232B'," +
"'#C1232B','#C1232B','#C1232B','#C1232B','#C1232B','#C1232B','#C1232B'," +
"'#C1232B','#C1232B','#C1232B','#C1232B','#C1232B','#C1232B','#C1232B'," +
"'#C1232B','#C1232B','#C1232B','#C1232B','#C1232B','#C1232B','#C1232B'," +
"'#26C0C0'];return colorList[params.dataIndex]}}},");*/
info.append("itemStyle: {normal: {barBorderRadius :5 }},");

}else{
/*info.append("itemStyle: {normal: {color: function(params) {var colorList = " +
"['#33FFFF','#33FFFF','#33FFFF','#33FFFF','#33FFFF','#33FFFF','#33FFFF'," +
"'#33FFFF','#33FFFF','#33FFFF','#33FFFF','#33FFFF','#33FFFF','#33FFFF'," +
"'#33FFFF','#33FFFF','#33FFFF','#33FFFF','#33FFFF','#33FFFF','#33FFFF'," +
"'#33FFFF','#33FFFF','#33FFFF','#33FFFF','#33FFFF','#33FFFF','#33FFFF'," +
"'#33FFFF','#33FFFF','#33FFFF','#33FFFF','#33FFFF','#33FFFF','#33FFFF'," +
"'#33FFFF','#33FFFF','#33FFFF','#33FFFF','#33FFFF','#33FFFF','#33FFFF'," +
"'#26C0C0'];return colorList[params.dataIndex]}}},");*/
}

info.append("data:[ ");
Map<String, Integer>map2 = (Map<String, Integer>) entry.getValue();

for(Entry<String, Integer> entry1:map2.entrySet()){
String key = entry1.getKey();
String key1=key.replaceAll("市", "").replaceAll("省", "").replaceAll("维吾尔自治区", "").replaceAll("自治区", "").replaceAll("壮族自治区", "").replaceAll("", "").replace("壮族", "").replace("回族", "");
map3.put(key1, map2.get(entry1.getKey()));
}

int j=0;
for(Entry<String, Integer> entry2:map3.entrySet()){  //2-- for start
j++;
info.append(entry2.getValue());

if (j!=map3.size()) {
info.append(",");
}else {
info.append("");
}
}//2-- for end
info.append(" ]");
info.append(",markPoint : {data : [{type : 'max', name: '最大值'},{type : 'min', name: '最小值'} ]  },  markLine : { data : [     {type : 'average', name: '平均值'}  ]      }");
info.append(" }");
if(i!=map.size()){
info.append(",");
}else {
info.append("");
}
}//1--for end
info.append("] ");
}
int t = 0;
for(Entry<String, Integer> entry2:map3.entrySet()){  //2-- for start
t++;
if(t%2==0){
dateList.add("\n"+entry2.getKey());
}else{
dateList.add(entry2.getKey());
}
}
resultMap.put("title", title);
resultMap.put("legend", legendList);//图例
resultMap.put("date", dateList);//日期
resultMap.put("num",info.toString());//获取图形数据信息( series:data信息)
//JSONObject json = JSONObject.fromObject(resultMap);
//ObjectMapper objectMapper = new ObjectMapper();
//String json = objectMapper.writeValueAsString(resultMap);
//return json;
return resultMap;
}

public Map<String, Object> getProvinceDataScatter(Map<String, Map<String, Integer>> map,String title) throws JsonGenerationException, JsonMappingException, IOException {
Map<String, Object> resultMap = new HashMap<String, Object>();//定义存放图形信息的map集合
List<String> legendList = new ArrayList<String>();//定义存放图例的list集合
List<String> dateList = new ArrayList<String>(); //定义存放日期的list集合

Map<String, Integer>map3 = new HashMap<String, Integer>();
//Map<String, Object> mapkeydate = new LinkedHashMap<String, Object>();//定义存放日期map集合 key:日期; value:0
//2-- for end
StringBuffer info = new StringBuffer();
if(map!=null && map.size()!=0) {
int i = 0;
info.append("[");
for(Entry<String, Map<String, Integer>> entry : map.entrySet()) {//1-- for start
i++;
legendList.add(entry.getKey());//图例
info.append("{name:'");
info.append(entry.getKey());
info.append("',");
info.append("type:'");
info.append("scatter");
info.append("',");
info.append("data:[ ");
Map<String, Integer>map2 = (Map<String, Integer>) entry.getValue();

for(Entry<String, Integer> entry1:map2.entrySet()){
String key = entry1.getKey();
String key1=key.replaceAll("市", "").replaceAll("省", "").replaceAll("维吾尔自治区", "").replaceAll("自治区", "").replaceAll("壮族自治区", "").replaceAll("", "").replace("壮族", "").replace("回族", "");
map3.put(key1, map2.get(entry1.getKey()));
}

int j=0;
for(Entry<String, Integer> entry2:map3.entrySet()){  //2-- for start
j++;
info.append("['");
info.append(entry2.getKey());

info.append("',");
info.append(entry2.getValue());
info.append("]");

if (j!=map3.size()) {
info.append(",");
}else {
info.append("");
}
}//2-- for end

info.append(" ] ");
info.append(",markPoint : {data : [{type : 'max', name: '最大值'},{type : 'min', name: '最小值'} ]  },  markLine : { data : [     {type : 'average', name: '平均值'}  ]      }");
info.append("  }");
if(i!=map.size()){
info.append(",");
}else {
info.append("");
}
}//1--for end
info.append("] ");
}
int t = 0;
for(Entry<String, Integer> entry2:map3.entrySet()){  //2-- for start
t++;
if(t%2==0){
dateList.add("\n"+entry2.getKey());
}else{
dateList.add(entry2.getKey());
}
}

resultMap.put("title", title);
resultMap.put("legend", legendList);//图例
resultMap.put("date", dateList);//日期
resultMap.put("num",info.toString());//获取图形数据信息( series:data信息)
//JSONObject json = JSONObject.fromObject(resultMap);
//ObjectMapper objectMapper = new ObjectMapper();
//String json = objectMapper.writeValueAsString(resultMap);
//return json;
return resultMap;
}

public Map<String, Object> getRadarData1(Map<String, Map<String, Integer>> map,String format1,String format2,String startDate,String endDate,String title,int type) throws JsonGenerationException, JsonMappingException, IOException {
Map<String, Object> resultMap = new HashMap<String, Object>();//定义存放图形信息的map集合
List<String> legendList = new ArrayList<String>();//定义存放图例的list集合
List<String> dateList = new ArrayList<String>(); //定义存放日期的list集合
StringBuffer text = new StringBuffer();
TimeFormat timeFormat = TimeFormat.getInstance();
Map<String, Object> mapkeydate = new LinkedHashMap<String, Object>();//定义存放日期map集合 key:日期; value:0
int days = timeFormat.getCalDateDiff(format1, startDate, endDate, 1);
for(int i = days;i>=0;--i) { //得到指定范围的时间
String date = timeFormat.getDate("yyyyMMdd", format1, endDate,i>0?-i:0);
mapkeydate.put(date,0);
String date_list = timeFormat.getDate(format2, format1, endDate,i>0?-i:0);
dateList.add(date_list);
}
StringBuffer info = new StringBuffer();
if(map!=null && map.size()!=0) {
int i = 0;
int value = 0;
for(Entry<String, Map<String, Integer>> result : map.entrySet()) {//1-- for start
//拼接虫洞图棱角
text.append(" { text: '");
text.append(result.getKey());

if(i!=map.size()){
text.append("'},");
}else{
text.append("'}");
}
//开始遍历内部map
for(Entry<String, Integer> resultin : result.getValue().entrySet()) {//1-- for start
//拼接时间
legendList.add(resultin.getKey());
if(resultin.getKey()==null){
value = 0;
}else{
value = resultin.getValue();
}

}
info.append(value);
if(i!=map.size()){
info.append(",");
}else{
info.append("");
}
i++;
}//1--for end
}
//给name赋值 时间
String name = "";
for(int i = 0; i<legendList.size(); i++){
name = name+ legendList.get(i)+",";
}
resultMap.put("name", name);
resultMap.put("text", text);
resultMap.put("title", title);
resultMap.put("legend", legendList);//图例
resultMap.put("date", dateList);//日期
resultMap.put("num",info.toString());//获取图形数据信息( series:data信息)
//JSONObject json = JSONObject.fromObject(resultMap);
//ObjectMapper objectMapper = new ObjectMapper();
//String json = objectMapper.writeValueAsString(resultMap);
//return json;
return resultMap;
}
/**
* 获取雷达图
* @param statMap
* @param format1
* @param format2
* @param format3
* @param startDate
* @param endDate
* @param title
* @param type
* @return
* @throws JsonGenerationException
* @throws JsonMappingException
* @throws IOException
*/
public Map<String, Object> getRadarData(Map<String, Map<String, Integer>> statMap,String format1,String format2,String format3,String startDate,String endDate,String title,int type) throws JsonGenerationException, JsonMappingException, IOException {
Map<String, Object> resultMap = new HashMap<String, Object>();
List<String> y_List = new ArrayList<String>(); //定义存放y轴的list集合
List<String> legend = new ArrayList<String>(); //定义图例
List<String> x_List = new ArrayList<String>(); //定义存放x轴的list集合
List<List<String>> list = new ArrayList<List<String>>();
TimeFormat timeFormat = TimeFormat.getInstance();
Map<String, Object> resultStatMap = new LinkedHashMap<String, Object>();//定义存最终数据放结果集的map
int days = timeFormat.getCalDateDiff(format1, startDate, endDate, 1);
for(int i =0;i<=days;i++) { //得到指定范围的时间
String date = timeFormat.getDate(format3, format1, endDate,i>0?-i:0);
resultStatMap.put(date,0);
String date_list = timeFormat.getDate(format2, format1, endDate,i>0?-i:0);
x_List.add(date_list);
}
Map<String, Object> resultMaxMap =resultStatMap;
//定义顶点的最大值
int max = 0;
Set<String> keys = statMap.keySet();
for(String key :keys){
y_List = new ArrayList<String>();
legend.add("'"+key+"'");//图例
Set<String> inkeys = resultStatMap.keySet();
for(String inkey :inkeys){
if(statMap.get(key).get(inkey)==null){
resultStatMap.put(inkey, 0);
}else{
resultStatMap.put(inkey, statMap.get(key).get(inkey));
if(max <= statMap.get(key).get(inkey)){
max = statMap.get(key).get(inkey);
resultMaxMap.put(inkey, max);
}
}
y_List.add(resultStatMap.get(inkey).toString());//Y轴
}
list.add(y_List);
}
//顶点
StringBuffer dingdian = new StringBuffer();
Set<String> inkeys = resultStatMap.keySet();
int i=0;
for(String inkey :inkeys){
dingdian.append("{ text: '"+inkey.substring(inkey.length()-4,inkey.length()).substring(0, 2)+"/"+inkey.substring(inkey.length()-2,inkey.length())+"', max: "+resultMaxMap.get(inkey)+"}");
if(i==6){
break;
}
dingdian.append(",");
i++;
}
resultMap.put("list", list);
resultMap.put("legend", legend);
resultMap.put("x_List", x_List);
resultMap.put("title", title);
resultMap.put("dingdian", dingdian);
return resultMap;
}
/**
* 封装力引导关系图的数据
* @param keywordsStatMap
* @return
*/
public Map<String,Object> getRelationKeywords(Map<String, Integer> keywordsStatMap,String peopleName){
Map<String, Object> resultMap = new HashMap<String, Object>();//定义存放饼图信息的map集合
List<Map<String, Object>> nodeList = new ArrayList<Map<String, Object>>();
List<Map<String, Object>> edgeList = new ArrayList<Map<String, Object>>();

int i = 0;
for(Map.Entry<String, Integer> statEntry : keywordsStatMap.entrySet()){
i++;
String statKey = statEntry.getKey();
Integer statValue = statEntry.getValue();
Map<String, Object> nodeMap = new HashMap<String, Object>();
if(nodeList.isEmpty()){
nodeMap.put("id", i);
nodeMap.put("name", peopleName);
nodeMap.put("x", "-266.82776");
nodeMap.put("y", "299.6904");
nodeMap.put("num", 20);
nodeList.add(nodeMap);
}else{
nodeMap.put("id", i);
nodeMap.put("name", statKey);
nodeMap.put("x", coordinate("-266.82776", null,200,(i*15)));
nodeMap.put("y", coordinate(null, "299.6904",200,(i*15)));
nodeMap.put("num", statValue);
nodeList.add(nodeMap);
}
Map<String, Object> edgeMap = new HashMap<String, Object>();
if(edgeList.isEmpty()){
edgeMap.put("id", i);
edgeMap.put("name", peopleName);
edgeMap.put("sourceID", 1);
edgeMap.put("targetID", i);
edgeList.add(edgeMap);
}else{
edgeMap.put("id", i);
edgeMap.put("name", statKey);
edgeMap.put("sourceID", 1);
edgeMap.put("targetID", i);
edgeList.add(edgeMap);
}
}
resultMap.put("nodes", nodeList);
resultMap.put("edges", edgeList);
return resultMap;
}
/**
* 算出周边点的坐标
* @param x
* @param y
* @param r
* @param ao
* @return
*/
public static String coordinate(String x, String y,int r,int ao){
String str="";
double x1=0;
double y1=0;
if(null!=y&&!"".equals(y)){
double y0=Double.parseDouble(y);
y1   =   y0+r*Math.sin(ao*3.14/180);
str = String.valueOf(y1);
}
if(null!=x&&!"".equals(x)){
double x0=Double.parseDouble(x);
x1   =   x0+r*Math.cos(ao*3.14/180);
str=String.valueOf(x1);
}
return str;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  数据
相关文章推荐