jofc2 API生成json数据

private void drawPie(Chart chart, List<GraphicDataset> data) {
        PieChart elements = new PieChart();
        elements.setGradientFill(true);
        elements.setTooltip("#val# / #total#<br> #percent#");
        List<String> lstColor = new ArrayList<String>();
        int sliceIndex = 0;
        for (GraphicDataset ds : data) {
            elements.addSlice(ds.getValue(), ds.getCategoryName());
            lstColor.add(colors[sliceIndex++]);
        }
        elements.setColours(lstColor);
        chart.addElements(elements);
    }
    private void drawLine(Chart chart, Map<String, List<GraphicDataset>> dataMap) {
        double max = 0;
        int barIndex = 0;
        java.util.Iterator<String> keyIter = dataMap.keySet().iterator();
        String seriesName;
        List<GraphicDataset> lstData = null;
        while (keyIter.hasNext()) {
            seriesName = keyIter.next();
            LineChart elements = new LineChart();
            elements.setGradientFill(true);
            elements.setText(seriesName);
            lstData = dataMap.get(seriesName);
            for (GraphicDataset ds : lstData) {
                LineChart.Dot dot = new LineChart.Dot(ds.getValue(), colors[barIndex]);
                elements.addDots(dot);
                max = Math.max(max, ds.getValue().doubleValue());
            }
            elements.setColour(colors[barIndex++]);
            chart.addElements(elements);
        }

        if (lstData != null) {
            XAxis xas = new XAxis();
            for (GraphicDataset ds : lstData) {
                xas.addLabels(ds.getCategoryName());
            }
            chart.setXAxis(xas);
        }

        YAxis y = new YAxis();
        double step = max / 10;
        y.setSteps(step);
        y.setMax(max + step);
        chart.setYAxis(y);
    }
    private void drawBar(Chart chart, Map<String, List<GraphicDataset>> dataMap) {
        double max = 0;
        int barIndex = 0;
        java.util.Iterator<String> keyIter = dataMap.keySet().iterator();
        String seriesName;
        List<GraphicDataset> lstData = null;
        while (keyIter.hasNext()) {
            seriesName = keyIter.next();
            BarChart elements = new BarChart(Style.GLASS);// BarChart(Style.THREED);
            elements.setGradientFill(true);
            elements.setText(seriesName);
            lstData = dataMap.get(seriesName);
            for (GraphicDataset ds : lstData) {
                BarChart.Bar bar = new BarChart.Bar(ds.getValue(), colors[barIndex]);
                elements.addBars(bar);
                max = Math.max(max, ds.getValue().doubleValue());
            }
            elements.setColour(colors[barIndex++]);
            chart.addElements(elements);
        }

        if (lstData != null) {
            XAxis xas = new XAxis();
            for (GraphicDataset ds : lstData) {
                xas.addLabels(ds.getCategoryName());
            }
            chart.setXAxis(xas);
        }

        YAxis y = new YAxis();
        double step = max / 10;
        y.setSteps(step);
        y.setMax(max + step);
        chart.setYAxis(y);
    }
    private void drawHorizontalBar(Chart chart, Map<String, List<GraphicDataset>> dataMap) {
        double max = 0;
        int barIndex = 0;
        java.util.Iterator<String> keyIter = dataMap.keySet().iterator();
        String seriesName;
        List<GraphicDataset> lstData = null;
        while (keyIter.hasNext()) {
            seriesName = keyIter.next();
            HorizontalBarChart elements = new HorizontalBarChart();
            elements.setText(seriesName);
            elements.setGradientFill(true);
            lstData = dataMap.get(seriesName);
            for (GraphicDataset ds : lstData) {
                // new HorizontalBarChart.Bar(ds.getValue())
                elements.addBar(0, ds.getValue());
                max = Math.max(max, ds.getValue().doubleValue());
            }
            elements.setColour(colors[barIndex++]);
            chart.addElements(elements);
            break;
        }

        if (lstData != null) {
            YAxis yas = new YAxis();
            for (GraphicDataset ds : lstData) {
                yas.addLabels(ds.getCategoryName());
            }
            yas.setOffset(true);
            chart.setYAxis(yas);
        }

        XAxis xas = new XAxis();
        double step = max / 10;
        xas.setSteps(step);
        xas.setMax(max + step);
        chart.setXAxis(xas);

        System.out.println(chart.toDebugString());
    }
    private void drawStackBar(Chart chart, Map<String, List<GraphicDataset>> dataMap) {
        double max = 0, tempNum = 0;
        int barIndex = 0;
        // 将Map的key由seriesName变为categoryName
        java.util.Iterator<String> keyIter = dataMap.keySet().iterator();
        List<String> keyNames = new ArrayList<String>();
        String seriesName, categoryName;
        Map<String, List<GraphicDataset>> tempMap =
                new LinkedHashMap<String, List<GraphicDataset>>();
        List<GraphicDataset> lstData = null;
        while (keyIter.hasNext()) {
            seriesName = keyIter.next();
            keyNames.add(seriesName);
            lstData = dataMap.get(seriesName);
            for (GraphicDataset ds : lstData) {
                categoryName = ds.getCategoryName();
                if (!tempMap.containsKey(categoryName)) {
                    tempMap.put(categoryName, new ArrayList<GraphicDataset>());
                }
                tempMap.get(categoryName).add(ds);
            }
        }

        StackedBarChart elements = new StackedBarChart();
        elements.setGradientFill(true);
        chart.addElements(elements);

        for (String keyName : keyNames) {
            StackedBarChart.Key key = new StackedBarChart.Key(colors[barIndex++], keyName, 12);
            elements.addKeys(key);
        }

        XAxis xas = new XAxis();
        keyIter = tempMap.keySet().iterator();
        while (keyIter.hasNext()) {
            categoryName = keyIter.next();
            xas.addLabels(categoryName);
            StackedBarChart.Stack stack = new StackedBarChart.Stack(); // 一个堆
            elements.addStack(stack);
            lstData = tempMap.get(categoryName);
            tempNum = 0;
            barIndex = 0;
            for (GraphicDataset ds : lstData) {
                StackedBarChart.StackValue stackValue =
                        new StackedBarChart.StackValue(ds.getValue(), colors[barIndex++]);
                stack.addStackValues(stackValue);
                tempNum += ds.getValue().doubleValue();
            }

            max = Math.max(max, tempNum);
        }

        chart.setXAxis(xas);

        YAxis y = new YAxis();
        double step = max / 10;
        y.setSteps(step);
        y.setMax(max + step);
        chart.setYAxis(y);

        tempMap = null;
        lstData = null;
    }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值