调用之前的工具类V63 漏斗图


                Sheet sheet = ExcelDataUtils.convertDataListToSheetsa(chartDateTto.getDataList());
                String chartValue = chartDateTto.getChartValue();
                //漏斗图
                ChartSmartVo chartV63 = getChartV63(ExcelDataUtils.getData(sheet), chartValue);
                ArrayList<ChartSmartVo> newList = new ArrayList<>();
                newList.add(chartV63);
                System.out.println(chartV63.getConfigValue().toString());
  public static Sheet convertDataListToSheetsa(List<Map<String, Object>> dataList) {
        Workbook workbook = new XSSFWorkbook();
        Sheet sheet = workbook.createSheet();

        for (int i = 0; i < 8; i++) {
            sheet.createRow(i);
        }

        int rowIndex = 8;
        for (Map<String, Object> data : dataList) {
            Row row = sheet.createRow(rowIndex++);
            int cellIndex = 0;
            for (Map.Entry<String, Object> entry : data.entrySet()) {
                Cell cell = row.createCell(cellIndex++);
                setCellValues(cell, entry.getValue());
            }
        }

        return sheet;
    }

    private static void setCellValues(Cell cell, Object value) {
        if (value instanceof String) {
            cell.setCellValue((String) value);
        } else if (value instanceof Number) {
            cell.setCellValue(((Number) value).doubleValue());
        } else if (value instanceof Boolean) {
            cell.setCellValue((Boolean) value);
        } else if (value instanceof java.util.Date) {
            cell.setCellValue((java.util.Date) value);
        } else {
            cell.setCellValue(value != null ? value.toString() : "");
        }
    }
    private ChartSmartVo getChartV63(List<List<String>> getdata, String chartValue) {
        List<JSONObject> list = new ArrayList<>();
        List<String> name = new ArrayList<>();

        // Process the input data and construct the list of JSONObjects
        for (int i = 0; i < getdata.size(); i++) {
            List<String> strings = getdata.get(i);
            JSONObject jsonObject = new JSONObject();
            for (int i1 = 0; i1 < strings.size(); i1++) {
                String s = strings.get(i1);
                if (org.apache.commons.lang3.ObjectUtils.isNotEmpty(s) && !s.equals("")) {
                    if (i1 == 0) {
                        jsonObject.put("name", s);
                        name.add(s);
                    } else if (i1 == 1) {
                        jsonObject.put("value", Double.parseDouble(s));
                    }
                }
            }
            list.add(jsonObject);
        }

        // Parse the chartValue JSON string
        JSONObject jsonObject = JSON.parseObject(chartValue);

        // Update the series data
        List<JSONObject> series = (List<JSONObject>) jsonObject.get("series");
        for (JSONObject jsonObject1 : series) {
            jsonObject1.put("data", list);
        }

        // Handle the legend data
        Object legendObject = jsonObject.get("legend");
        if (legendObject instanceof JSONObject) {
            JSONObject legend = (JSONObject) legendObject;
            legend.put("data", name);
            jsonObject.put("legend", legend);
        } else {
            // If "legend" is not a JSONObject, handle the case appropriately
            // For example, you might want to initialize it as an empty JSONObject
            JSONObject legend = new JSONObject();
            legend.put("data", name);
            jsonObject.put("legend", legend);
        }

        // Update the series data and create the ChartSmartVo object
        jsonObject.put("series", series);

        ChartSmartVo chartSmartVo = new ChartSmartVo();
        chartSmartVo.setConfigValue(JSON.toJSONString(jsonObject));
        return chartSmartVo;
    }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值