/**
* 可以了 好用的 多排 3D切面
*
* @param chartDateTto
* @return
* @throws Exception
*/
("/multi3DSectionBar/importData")
public AjaxResult multi3DSectionBar( ChartDateTto chartDateTto) throws Exception {
String chartValue = chartDateTto.getChartValue();
Integer configId = chartDateTto.getConfigId();
List<List<String>> getdata = extractDataFromListNullString(chartDateTto.getDataList());
// 获取seriesName列表
ArrayList<String> seriesName = new ArrayList<>();
for (List<String> getdatum : getdata) {
String first = getdatum.get(0);
seriesName.add(first);
}
seriesName.remove(0);
if (configId == 49) {
Sheet sheet = ExcelUtils.convertDataListToSheetRemoveNineAndOne(chartDateTto.getDataList());
List<List<String>> getdatas = ExcelDataUtils.getData(sheet);
if (CollectionUtils.isEmpty(getdatas)) {
return AjaxResult.error("请填充数据");
}
List<String> xList = new ArrayList<>();
List<String> yList = new ArrayList<>();
List<Object> pointCuts = new ArrayList<>();
List<String> sections = getdatas.get(1);
getdatas.remove(1);
for (int i = 1; i < sections.size(); i++) {
String s = sections.get(i);
if (!ObjectUtils.isEmpty(s) && !s.equals("")) {
pointCuts.add(Double.parseDouble(s));
}
}
List<List<String>> dataList = new ArrayList<>();
for (int i = 0; i < getdatas.size(); i++) {
List<String> ss = getdatas.get(i);
if (!CollectionUtils.isEmpty(ss) && !ss.equals("")) {
if (i == 0) {
for (int i1 = 1; i1 < ss.size(); i1++) {
String y = ss.get(i1);
if (!ObjectUtils.isEmpty(y) && !y.equals("")) {
yList.add(y);
}
}
} else {
String x = ss.get(0);
if (!ObjectUtils.isEmpty(x) && !x.equals("")) {
xList.add(x);
}
getdatas.get(i).remove(0);
dataList.add(getdatas.get(i));
}
}
}
List<ChartXDataVo> xData = new ArrayList<>();
List<List<Object>> newDataLists = new ArrayList<>();
for (int i = 0; i < xList.size(); i++) {
String x = xList.get(i);
List<List<Object>> newDataList = new ArrayList<>();
for (int j = 0; j < yList.size(); j++) {
String s = dataList.get(i).get(j);
if (!ObjectUtils.isEmpty(s) && !s.equals("")) {
String y = yList.get(j);
List<Object> cellList = new ArrayList<>();
cellList.add(x);
cellList.add(y);
cellList.add(Double.parseDouble(s));
List<Object> cellList1 = new ArrayList<>();
cellList1.add(x);
cellList1.add(y);
cellList1.add(Double.parseDouble(s));
newDataLists.add(cellList1);
newDataList.add(cellList);
}
}
ChartXDataVo chartXDataVo = new ChartXDataVo();
chartXDataVo.setSource(newDataList);
xData.add(chartXDataVo);
}
JSONObject jsonObject = JSON.parseObject(chartDateTto.getChartValue());
jsonObject.put("dataset", xData);
JSONObject legend = jsonObject.getJSONArray("legend").getJSONObject(0);
if (legend == null) {
legend = new JSONObject();
}
// 更新 legend 的 data
JSONArray legendDataArray = new JSONArray();
for (String xName : xList) {
JSONObject dataItem = new JSONObject();
dataItem.put("name", xName);
legendDataArray.add(dataItem);
}
legend.put("data", legendDataArray);
jsonObject.getJSONArray("legend").set(0, legend);
JSONArray seriesArray = jsonObject.getJSONArray("series");
if (seriesArray == null) {
seriesArray = new JSONArray();
}
List<JSONObject> seriesList = new ArrayList<>();
for (int i = 0; i < xList.size(); i++) {
JSONObject seriesObject = seriesArray.getJSONObject(0);
if (seriesObject != null) {
JSONObject newSeriesObject = new JSONObject();
newSeriesObject.putAll(seriesObject);
newSeriesObject.put("datasetIndex", i);
newSeriesObject.put("name", xList.get(i)); // 将 name 字段设置为 xList 中的值
seriesList.add(newSeriesObject);
}
}
JSONObject seriesObject = seriesArray.getJSONObject(3);
if (seriesObject != null) {
for (int i = 0; i < pointCuts.size(); i++) {
JSONObject jsonObject1 = new JSONObject();
jsonObject1.putAll(seriesObject);
List<List<Object>> list = new ArrayList<>();
for (List<Object> objects : newDataLists) {
List<Object> objects1 = new ArrayList<>(objects);
objects1.set(2, pointCuts.get(i));
list.add(objects1);
}
jsonObject1.put("data", list);
seriesList.add(jsonObject1);
}
}
jsonObject.put("series", seriesList);
JSONObject grid3D = jsonObject.getJSONObject("grid3D");
if (grid3D == null) {
grid3D = new JSONObject();
}
if (xList.size() > 10 || yList.size() > 10) {
grid3D.put("boxWidth", xList.size() * 8);
grid3D.put("boxDepth", yList.size() * 8);
} else {
grid3D.put("boxWidth", xList.size() * 20);
grid3D.put("boxDepth", yList.size() * 20);
}
jsonObject.put("grid3D", grid3D);
System.out.println("我是configId=49处理之前的" + JSON.toJSONString(jsonObject));
System.out.println("-----------代码处理部分----------------");
ArrayList<ChartSmartVo> newList = new ArrayList<>();
ChartSmartVo chartSmartVo = new ChartSmartVo();
chartSmartVo.setConfigValue(JSON.toJSONString(jsonObject));
newList.add(chartSmartVo);
System.out.println("我是configId=49处理之后的" + JSON.toJSONString(jsonObject));
return AjaxResult.success(newList);
}
// 更新series
ObjectNode updatedJson = com.chart.web.controller.chart.sta.JsonsUtil.updateSeriesInJson(chartValue, seriesName);
// 更新 legend 中 data 数组的 name 字段
updateLegendDataNames(updatedJson, seriesName);
// 生成并更新 dataset
ArrayNode datasetArray = com.chart.web.controller.chart.sta.JsonsUtil.generateDataset(getdata);
updatedJson.set("dataset", datasetArray);
ArrayList<ChartSmartVo> newList = new ArrayList<>();
ChartSmartVo chartSmartVo = new ChartSmartVo();
chartSmartVo.setConfigValue(JSON.toJSONString(updatedJson));
newList.add(chartSmartVo);
System.out.println(JSON.toJSONString(updatedJson));
return AjaxResult.success(newList);
}
echarts 多拍3D柱状图和切面图
最新推荐文章于 2024-09-26 13:36:15 发布