String chartValue = chartDateTto.getChartValue();
List<List<String>> lists = ChartDataUtils.extractDataFromList(chartDateTto.getDataList());
ObjectMapper objectMapper = new ObjectMapper();
JsonNode chartValueJson = objectMapper.readTree(chartValue);
ArrayNode dataset = (ArrayNode) chartValueJson.path("dataset");
System.out.println("我是dataset" + dataset);
for (List<String> list : lists) {
System.out.println("我是list" + list);
}
dataset = ChartDataUtils.updateDatasetSourcesCyclic(dataset, lists, objectMapper);
if (!lists.isEmpty() && !lists.get(0).isEmpty()) {
lists.get(0).remove(0);
}
ArrayNode seriesArray = (ArrayNode) chartValueJson.path("series");
if (seriesArray.size() > 1) {
while (seriesArray.size() > 1) {
seriesArray.remove(1);
}
}
int firstObjectRemainingElements = lists.isEmpty() ? 0 : lists.get(0).size();
JsonNode firstSeriesObject = seriesArray.get(0);
for (int i = 1; i < firstObjectRemainingElements; i++) {
seriesArray.add(firstSeriesObject.deepCopy());
}
for (int i = 0; i < seriesArray.size(); i++) {
ObjectNode seriesObject = (ObjectNode) seriesArray.get(i);
if (seriesObject.has("datasetIndex")) {
seriesObject.put("datasetIndex", i);
} else {
seriesObject.put("datasetIndex", i);
}
}
JsonNode legend = chartValueJson.path("legend");
ChartDataUtils.updateLegendData(legend, lists);
for (int i = 0; i < firstObjectRemainingElements; i++) {
((ObjectNode) seriesArray.get(i)).put("name", lists.get(0).get(i));
}
ObjectNode jsonNode = (ObjectNode) objectMapper.readTree(chartValue);
JsonNode colorNode = jsonNode.path("color");
List<String> baseColors = new ArrayList<>();
if (colorNode.isArray()) {
for (JsonNode color : colorNode) {
String colorValue = color.asText();
baseColors.add(colorValue);
}
}
int beforeSize = baseColors.size();
int afterSize = lists.get(0).size();
if (beforeSize < afterSize) {
chartValueJson = ColorUtils.processChartColorsHert(JSON.toJSONString(chartValueJson), afterSize);
}
String updatedChartValue = chartValueJson.toString();
ArrayList<ChartSmartVo> newList = new ArrayList<>();
ChartConfigs configs = chartConfigsService.getById(chartDateTto.getConfigId());
ChartSmartVo chartSmartVo = new ChartSmartVo();
chartSmartVo.setConfigId(configs.getId());
chartSmartVo.setConfigName(configs.getConfigName());
chartSmartVo.setConfigValue(updatedChartValue);
chartSmartVo.setChartTypeId(configs.getChartTypeId());
newList.add(chartSmartVo);
System.out.println(updatedChartValue);
return AjaxResult.success(newList);