1.越线图
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
package com.njcn.echarts.json;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
import com.google.gson.Gson;
|
||||
import com.njcn.echarts.pojo.bo.TolerateData;
|
||||
import com.njcn.echarts.pojo.constant.PicCommonData;
|
||||
import org.icepear.echarts.Option;
|
||||
@@ -14,6 +17,7 @@ import org.icepear.echarts.components.coord.cartesian.LogAxis;
|
||||
import org.icepear.echarts.components.coord.cartesian.ValueAxis;
|
||||
import org.icepear.echarts.components.grid.Grid;
|
||||
import org.icepear.echarts.components.legend.Legend;
|
||||
import org.icepear.echarts.components.series.LineStyle;
|
||||
import org.icepear.echarts.components.text.Label;
|
||||
import org.icepear.echarts.components.title.Title;
|
||||
import org.icepear.echarts.components.tooltip.Tooltip;
|
||||
@@ -21,7 +25,11 @@ import org.icepear.echarts.origin.util.SeriesOption;
|
||||
import org.icepear.echarts.render.Engine;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
/**
|
||||
@@ -517,4 +525,71 @@ public class LineGenerator {
|
||||
instantOption.setSeries(new LineSeries[]{aSeries, bSeries, cSeries});
|
||||
return ENGINE.renderJsonOption(instantOption);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Description: App越线指标图(单相)
|
||||
* @param title 标题
|
||||
* @param values 数据值
|
||||
* @param limitName 限制值标题
|
||||
* @param limit 限制值
|
||||
* @return: java.lang.String
|
||||
* @Author: wr
|
||||
* @Date: 2023/11/6 11:38
|
||||
*/
|
||||
public static String generateSteadyTargetOption(String title,Map<String ,List<List<Object>>> values,String limitName,List<List<Object>> limit) {
|
||||
Option persistentTimeOption = new Option();
|
||||
//取消渲染动画
|
||||
persistentTimeOption.setAnimation(false);
|
||||
//背景色
|
||||
persistentTimeOption.setBackgroundColor(PicCommonData.PIC_BACK_COLOR);
|
||||
//标题
|
||||
persistentTimeOption.setTitle(new Title().setLeft(PicCommonData.CENTER).setText(title));
|
||||
//设置图例
|
||||
List<String> name = values.keySet().stream().collect(Collectors.toList());
|
||||
name.add(limitName);
|
||||
persistentTimeOption.setLegend(new Legend().setData(name.stream().toArray(String[]::new)).setLeft(10).setShow(true));
|
||||
//设置边距
|
||||
persistentTimeOption.setGrid(new Grid().setLeft("3%").setRight("5%").setBottom("3%").setContainLabel(true));
|
||||
//横坐标
|
||||
persistentTimeOption.setXAxis(new CategoryAxis()
|
||||
.setType("time")
|
||||
.setName("(时间)")
|
||||
.setBoundaryGap(false)
|
||||
);
|
||||
persistentTimeOption.setColor(new String[]{"#CCC","#A0522D"});
|
||||
Integer max=0;
|
||||
if(CollUtil.isNotEmpty(limit)){
|
||||
Integer num = (Integer)limit.get(0).get(1);
|
||||
max=(int)(num * 0.2) + num;
|
||||
}
|
||||
//纵坐标
|
||||
persistentTimeOption.setYAxis(new ValueAxis()
|
||||
.setAxisLine(new AxisLine().setShow(true))
|
||||
.setMin(0).setMax(max)
|
||||
.setNameTextStyle(new AxisNameTextStyle().setFontStyle("15px"))
|
||||
);
|
||||
List<SeriesOption> list=new ArrayList<>();
|
||||
values.forEach((key,value)->{
|
||||
LineSeries proportion = new LineSeries()
|
||||
.setName(key)
|
||||
.setType("line")
|
||||
.setSmooth(true)
|
||||
.setLabel(new BarLabel().setShow(true).setPosition("bottom"))
|
||||
.setData(value);
|
||||
list.add(proportion);
|
||||
});
|
||||
LineSeries proportion2 = new LineSeries()
|
||||
.setName(limitName)
|
||||
.setSmooth(true)
|
||||
.setLineStyle(new LineStyle().setColor("green").setWidth(1).setType("dashed").setOpacity(1))
|
||||
.setData(limit);
|
||||
list.add(proportion2);
|
||||
SeriesOption[] seriesOptions = list.stream().toArray(SeriesOption[]::new);
|
||||
persistentTimeOption.setSeries(new SeriesOption[]{proportion2, proportion2});
|
||||
System.out.println(persistentTimeOption.toString());
|
||||
String s = new Gson().toJson(persistentTimeOption);
|
||||
return ENGINE.renderJsonOption(persistentTimeOption);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -11,10 +11,7 @@ import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author hongawen
|
||||
@@ -358,5 +355,65 @@ public class DrawPicUtil {
|
||||
return drawPic(eventDensityJson, width, height);
|
||||
}
|
||||
|
||||
/***
|
||||
* 绘制App越线指标图(单相)
|
||||
* @author hongawen
|
||||
* @date 2023/6/21 11:01
|
||||
* @return String base64数据
|
||||
*/
|
||||
public String drawSteadyTargetPic(String title,Map<String ,List<List<Object>>> values,String limitName,List<List<Object>> limit) {
|
||||
return drawSteadyTargetPic(title, values, limitName, limit, 0, 0);
|
||||
}
|
||||
|
||||
/***
|
||||
* 绘制App越线指标图(单相)
|
||||
* @author hongawen
|
||||
* @date 2023/6/21 11:01
|
||||
* @return String base64数据
|
||||
*/
|
||||
public String drawSteadyTargetPic(String title,Map<String ,List<List<Object>>> values,String limitName,List<List<Object>> limit,int width, int height) {
|
||||
String instantJson = LineGenerator.generateSteadyTargetOption(title, values, limitName, limit);
|
||||
return drawPic(instantJson, width, height);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
DrawPicUtil util=new DrawPicUtil();
|
||||
List<List<Object>> values=new ArrayList<>();
|
||||
List<Object> a = new ArrayList() {{
|
||||
add("2023-10-10 00:10:00");
|
||||
add(12.3);
|
||||
}};
|
||||
values.add(a);
|
||||
List<Object> a1 = new ArrayList() {{
|
||||
add("2023-10-10 00:20:00");
|
||||
add(22.3);
|
||||
}};
|
||||
values.add(a1);
|
||||
List<Object> a2 = new ArrayList() {{
|
||||
add("2023-10-10 00:30:00");
|
||||
add(32.3);
|
||||
}};
|
||||
values.add(a2);
|
||||
|
||||
List<List<Object>> limit=new ArrayList<>();
|
||||
List<Object> b = new ArrayList() {{
|
||||
add("2023-10-10 00:10:00");
|
||||
add(40);
|
||||
}};
|
||||
limit.add(b);
|
||||
List<Object> b1 = new ArrayList() {{
|
||||
add("2023-10-10 00:20:00");
|
||||
add(40);
|
||||
}};
|
||||
limit.add(b1);
|
||||
List<Object> b2 = new ArrayList() {{
|
||||
add("2023-10-10 00:30:00");
|
||||
add(40);
|
||||
}};
|
||||
limit.add(b2);
|
||||
Map<String,List<List<Object>>> da = new HashMap<>();
|
||||
da.put("实际", new ArrayList<>());
|
||||
String s = util.drawSteadyTargetPic("电压", da, "限制", limit);
|
||||
System.out.println();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import com.njcn.event.file.pojo.dto.WaveDataDTO;
|
||||
import com.njcn.event.file.pojo.enums.WaveFileResponseEnum;
|
||||
import com.njcn.oss.constant.OssPath;
|
||||
import com.njcn.oss.utils.FileStorageUtil;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
@@ -23,7 +24,7 @@ import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Base64;
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -276,5 +277,18 @@ public class WavePicComponent {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* app越限指标图
|
||||
* @param title
|
||||
* @param values
|
||||
* @param limitName
|
||||
* @param limit
|
||||
* @return
|
||||
*/
|
||||
public String generateSteadyTargetImage(String title, Map<String ,List<List<Object>>> values, String limitName, List<List<Object>> limit) {
|
||||
String firstPic = drawPicUtil.drawSteadyTargetPic(title,values,limitName,limit);
|
||||
//将图片上传到minioss
|
||||
InputStream instantStream = IoUtil.toStream(firstPic, CharsetUtil.UTF_8);
|
||||
return fileStorageUtil.uploadStream(instantStream, OssPath.EVENT_WAVE_PIC, FileUtil.generateFileName("png"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
package com.njcn;
|
||||
|
||||
import com.njcn.echarts.util.DrawPicUtil;
|
||||
import com.njcn.event.file.component.WavePicComponent;
|
||||
import com.njcn.influx.imapper.DataFlickerMapper;
|
||||
import com.njcn.influx.pojo.po.DataFlicker;
|
||||
import com.njcn.oss.constant.OssPath;
|
||||
import com.njcn.oss.utils.FileStorageUtil;
|
||||
import com.njcn.redis.utils.RedisUtil;
|
||||
import lombok.SneakyThrows;
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -11,9 +14,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author hongawen
|
||||
@@ -28,6 +29,68 @@ public class OssTest extends BaseJunitTest {
|
||||
@Autowired
|
||||
private DataFlickerMapper dataFlickerMapper;
|
||||
|
||||
@Autowired
|
||||
private RedisUtil redisUtil;
|
||||
@Autowired
|
||||
private WavePicComponent component;
|
||||
|
||||
@Autowired
|
||||
private DrawPicUtil drawPicUtil;
|
||||
|
||||
@SneakyThrows
|
||||
@Test
|
||||
public void dadada() {
|
||||
List<List<Object>> values=new ArrayList<>();
|
||||
List<Object> a = new ArrayList() {{
|
||||
add("2023-10-10 00:10:00");
|
||||
add(12.3);
|
||||
}};
|
||||
values.add(a);
|
||||
List<Object> a1 = new ArrayList() {{
|
||||
add("2023-10-10 00:20:00");
|
||||
add(22.3);
|
||||
}};
|
||||
values.add(a1);
|
||||
List<Object> a2 = new ArrayList() {{
|
||||
add("2023-10-10 00:30:00");
|
||||
add(32.3);
|
||||
}};
|
||||
values.add(a2);
|
||||
|
||||
List<List<Object>> limit=new ArrayList<>();
|
||||
List<Object> b = new ArrayList() {{
|
||||
add("2023-10-10 00:10:00");
|
||||
add(40);
|
||||
}};
|
||||
limit.add(b);
|
||||
List<Object> b1 = new ArrayList() {{
|
||||
add("2023-10-10 00:20:00");
|
||||
add(40);
|
||||
}};
|
||||
limit.add(b1);
|
||||
List<Object> b2 = new ArrayList() {{
|
||||
add("2023-10-10 00:30:00");
|
||||
add(40);
|
||||
}};
|
||||
limit.add(b2);
|
||||
Map<String,List<List<Object>>> da = new HashMap<>();
|
||||
da.put("实际", new ArrayList<>());
|
||||
// String s = component.generateSteadyTargetImage("电压", da, "限制", limit);
|
||||
String s = drawPicUtil.drawSteadyTargetPic("电压", da, "限制", limit);
|
||||
System.out.println();
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
@Test
|
||||
public void dada() {
|
||||
|
||||
String dada = redisUtil.getStringByKey( "11");
|
||||
String adada = redisUtil.getStringByKey(5, "11");
|
||||
String dadaada = redisUtil.getStringByKey( "11");
|
||||
|
||||
System.out.println();
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
Reference in New Issue
Block a user