提交地图修改内容

This commit is contained in:
2022-08-18 15:06:18 +08:00
parent 61abbc251d
commit 36b76eabbe
10 changed files with 341 additions and 87 deletions

View File

@@ -1,85 +0,0 @@
package com.njcn.echarts;
import cn.hutool.json.JSONObject;
import com.github.abel533.echarts.code.Tool;
import com.github.abel533.echarts.code.Trigger;
import com.github.abel533.echarts.json.GsonOption;
import com.github.abel533.echarts.series.Line;
import com.njcn.common.pojo.response.HttpResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;
/**
* @author hongawen
* @version 1.0.0
* @date 2022年03月02日 18:59
*/
@Slf4j
public class TestUtil {
public static void main(String[] args) throws Exception {
JSONObject s = testEchart();
RestTemplate restTemplate = new RestTemplate();
ResponseEntity<HttpResult> forEntity = restTemplate.getForEntity("http://192.168.1.14:8910?opt={1}", HttpResult.class,s.toString());
System.out.println(forEntity.getBody().getData());
System.out.println(1);
}
public static JSONObject testEchart() {
String[] types = {"ECS", "实例", "CPU", "MEM"};
int[][] datas = {
{120, 132, 101, 134, 90, 230, 210},
{220, 182, 191, 234, 290, 330, 310},
{150, 232, 201, 154, 190, 330, 410},
{150, 232, 201, 154, 190, 330, 410}
};
String title = "资源增长情况";
GsonOption option = new GsonOption();
option.title().text(title).x("left");// 大标题、位置
// 提示工具
option.tooltip().trigger(Trigger.axis);// 在轴上触发提示数据
// 工具栏
option.toolbox().show(true).feature(Tool.saveAsImage);// 显示,保存为图片
option.legend(types);// 图例
com.github.abel533.echarts.axis.CategoryAxis category = new com.github.abel533.echarts.axis.CategoryAxis();// 轴分类
category.data("2019-03-09", "2019-03-02", "2019-03-16");
category.boundaryGap(false);// 起始和结束两端空白策略
//循环数据
for (int i = 0; i < types.length; i++) {
Line line = new Line();// 三条线,三个对象
String type = types[i];
line.name(type).stack("总量");
for (int j = 0; j < datas[i].length; j++) {
line.data(datas[i][j]);
}
option.series(line);
}
if (true) {// 横轴为类别、纵轴为值
option.xAxis(category);// x轴
// y轴
com.github.abel533.echarts.axis.ValueAxis ecsY = new com.github.abel533.echarts.axis.ValueAxis();
ecsY.name("ECS 台").position("left").axisLine().lineStyle().color("#1E90FF");
option.yAxis(ecsY);
} else {// 横轴为值、纵轴为类别
option.xAxis(new com.github.abel533.echarts.axis.ValueAxis());// x轴
option.yAxis(category);// y轴
}
String optionStr = option.toString().replace(" ", "");
System.out.println(optionStr);
JSONObject jsonObject = new JSONObject(optionStr);
return jsonObject;
}
}

View File

@@ -0,0 +1,84 @@
package com.njcn.echarts.bar;
import cn.hutool.json.JSONObject;
import com.github.abel533.echarts.Grid;
import com.github.abel533.echarts.axis.AxisLabel;
import com.github.abel533.echarts.axis.CategoryAxis;
import com.github.abel533.echarts.axis.SplitLine;
import com.github.abel533.echarts.axis.ValueAxis;
import com.github.abel533.echarts.code.AxisType;
import com.github.abel533.echarts.code.SeriesType;
import com.github.abel533.echarts.json.GsonOption;
import com.github.abel533.echarts.series.Bar;
import com.njcn.common.pojo.response.HttpResult;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
*
* 用于组装柱状图的option数据
*
* @author hongawen
* @version 1.0.0
* @date 2022年08月18日 10:58
*/
public class BarOptionUtil {
public static void main(String[] args) {
JSONObject optionJson = testEchart();
RestTemplate restTemplate = new RestTemplate();
ResponseEntity<HttpResult> forEntity = restTemplate.getForEntity("http://192.168.1.13:8910?opt={1}&width={2}&height={3}", HttpResult.class, optionJson.toString(), 714, 300);
//返回图片对应的base64
System.out.println(forEntity.getBody().getData());
System.out.println(1);
}
public static JSONObject testEchart() {
List<String> xName = Stream.of("江苏省", "四川省", "海南省").collect(Collectors.toList());
GsonOption option = new GsonOption();
// 大标题、位置
String title = "区域统计";
option.title().text(title).x("center");
// 提示工具
// 在轴上触发提示数据
option.tooltip().show(false);
// 工具栏
// 显示,保存为图片
option.toolbox().show(false);
// 图例
option.color("#FF7E50");
option.legend("暂降次数");
//控制图标在dataroom中的位置大小
option.grid(new Grid().left("3%").right("15%").bottom("5%").containLabel(true));
// 轴分类
CategoryAxis xAxis = new CategoryAxis();
xAxis.data(xName.toArray());
xAxis.splitLine(new SplitLine().show(false));
xAxis.name("地区\n(监测点数)");
xAxis.axisLabel(new AxisLabel().interval(0).show(true));
// 起始和结束两端空白策略
xAxis.boundaryGap(true);
// x轴
option.xAxis(xAxis);
//循环数据
Bar bar = new Bar();
bar.setType(SeriesType.bar);
bar.barMaxWidth(30);
bar.data(30, 48, 66);
option.series(bar);
// y轴
ValueAxis yAxis = new ValueAxis();
yAxis.name("(次)").type(AxisType.value);
option.yAxis(yAxis);
String optionStr = option.toString().replace(" ", "");
return new JSONObject(optionStr);
}
}

View File

@@ -0,0 +1,78 @@
package com.njcn.echarts.line;
import cn.hutool.json.JSONObject;
import com.github.abel533.echarts.Grid;
import com.github.abel533.echarts.axis.AxisLabel;
import com.github.abel533.echarts.axis.CategoryAxis;
import com.github.abel533.echarts.axis.SplitLine;
import com.github.abel533.echarts.axis.ValueAxis;
import com.github.abel533.echarts.code.AxisType;
import com.github.abel533.echarts.code.NameLocation;
import com.github.abel533.echarts.code.SeriesType;
import com.github.abel533.echarts.json.GsonOption;
import com.github.abel533.echarts.series.Bar;
import com.github.abel533.echarts.series.Line;
import com.njcn.common.pojo.response.HttpResult;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
* @author hongawen
* @version 1.0.0
* @date 2022年08月18日 14:39
*/
public class LineOptionUtil {
public static void main(String[] args) {
JSONObject optionJson = testEchart();
RestTemplate restTemplate = new RestTemplate();
ResponseEntity<HttpResult> forEntity = restTemplate.getForEntity("http://192.168.1.13:8910?opt={1}&width={2}&height={3}", HttpResult.class, optionJson.toString(), 714, 300);
//返回图片对应的base64
System.out.println(forEntity.getBody().getData());
System.out.println(1);
}
public static JSONObject testEchart() {
List<String> xName = Stream.of("0", "10%", "20%", "30%", "40%", "50%", "60%", "70%", "80%", "90%").collect(Collectors.toList());
GsonOption option = new GsonOption();
option.backgroundColor("#F9F9F9");
// 大标题、位置
String title = "暂降幅值的概率分布函数";
option.title().text(title).x("center");
// 提示工具
// 在轴上触发提示数据
option.tooltip().show(false);
// 工具栏
// 显示,保存为图片
option.toolbox().show(false);
// 图例
option.color("#FF7E50");
//控制图标在dataroom中的位置大小
option.grid(new Grid().left("3%").right("11%").bottom("5%").containLabel(true));
// 轴分类
CategoryAxis xAxis = new CategoryAxis();
xAxis.data(xName.toArray());
xAxis.nameGap(5);
xAxis.name("暂降幅值");
// 起始和结束两端空白策略
xAxis.boundaryGap(false);
// x轴
option.xAxis(xAxis);
Line line = new Line("暂降幅值");
line.setType(SeriesType.line);
line.data(0, 10, 11, 15, 16, 30, 48, 66, 75, 89);
option.series(line);
// y轴
ValueAxis yAxis = new ValueAxis();
yAxis.name("概率分布").type(AxisType.value).nameGap(50).nameLocation(NameLocation.middle).axisLabel(new AxisLabel().formatter("{value} %"));
option.yAxis(yAxis);
String optionStr = option.toString().replace(" ", "");
return new JSONObject(optionStr);
}
}

View File

@@ -0,0 +1,40 @@
package com.njcn.echarts.pojo.constant;
/**
* @author hongawen
* @version 1.0.0
* @date 2022年08月18日 10:39
*/
public interface PicCommonData {
/**
* 图形常见宽度
*/
Integer COMMON_ECHART_WIDTH = 714;
/**
* 图形常见高度
*/
Integer COMMON_ECHART_HEIGHT = 300;
/**
* word中图形常见宽度
*/
Integer COMMON_POI_WIDTH = 410;
/**
* word中图形常见高度
*/
Integer COMMON_POI_HEIGHT = 170;
/**
* word中地图常见高度
*/
Integer COMMON_POI_MAP_HEIGHT = 210;
}

View File

@@ -0,0 +1,27 @@
package com.njcn.echarts.pojo.enums;
import lombok.Getter;
/**
* @author hongawen
* @version 1.0.0
* @date 2021年12月20日 09:56
*/
@Getter
public enum EchartResponseEnum {
/**
* 画图模块异常响应码的范围:
*/
ECHART_COMMON_ERROR("A01001","后台远程绘制echart图异常")
;
private final String code;
private final String message;
EchartResponseEnum(String code, String message) {
this.code = code;
this.message = message;
}
}

View File

@@ -0,0 +1,46 @@
package com.njcn.echarts.util;
import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpStatus;
import com.njcn.common.pojo.exception.BusinessException;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.echarts.pojo.enums.EchartResponseEnum;
import lombok.RequiredArgsConstructor;
import org.springframework.http.RequestEntity;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;
import java.util.Objects;
/**
* @author hongawen
* @version 1.0.0
* @date 2022年08月18日 10:27
*/
@Component
@RequiredArgsConstructor
public class DrawPicUtil {
private final RestTemplate restTemplate;
/**
* 请求目标服务器绘制echart图
* @param url 目标url,例http://192.168.1.13:8910?opt={1}&width={2}&height={3}
* @param option 图形参数
* @param width 图形宽度
* @param height 图形高度
* @return 图形的base64数据
*/
public String drawPic(String url,String option,int width,int height){
ResponseEntity<HttpResult> result = restTemplate.getForEntity(url, HttpResult.class, option, width, height);
if(result.getStatusCodeValue() != HttpStatus.HTTP_OK || Objects.isNull(Objects.requireNonNull(result.getBody()).getData())){
throw new BusinessException(EchartResponseEnum.ECHART_COMMON_ERROR);
}
return result.getBody().getData().toString();
}
}

View File

@@ -0,0 +1,42 @@
var option1 = {
backgroundColor : '#f9f9f9',//背景色,
title : {
text : '暂降幅值的概率分布函数',
x : 'center'
},
animation : false,
legend : {
show : false,
data : [ '暂降幅值' ]
},
calculable : true,
xAxis : [ {
type : 'category',
boundaryGap : false,
name : '暂降幅值',
nameLocation : 'center',
nameGap : 20,
nameTextStyle : {
fontSize : 15
},
data : [ '0', '10%', '20%', '30%', '40%', '50%', '60%',
'70%', '80%', '90%' ]
} ],
yAxis : [ {
type : 'value',
name : '概率分布',
nameLocation : 'center',
nameGap : 40,
nameTextStyle : {
fontSize : 15
},
axisLabel : {
formatter : '{value} %'
}
} ],
series : [ {
name : '暂降幅值',
type : 'line',
data : eventValue
} ]
};