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 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; } }