All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.deepoove.poi.util.ChartUtils Maven / Gradle / Ivy

There is a newer version: 1.12.3-beta1
Show newest version
/*
 * Copyright 2014-2021 Sayi
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.deepoove.poi.util;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import org.apache.poi.xddf.usermodel.chart.XDDFChartData;
import org.apache.poi.xddf.usermodel.chart.XDDFValueAxis;
import org.apache.poi.xwpf.usermodel.XWPFChart;
import org.openxmlformats.schemas.drawingml.x2006.chart.CTOfPieChart;
import org.openxmlformats.schemas.drawingml.x2006.chart.CTPlotArea;
import org.openxmlformats.schemas.drawingml.x2006.chart.CTValAx;

import com.deepoove.poi.xwpf.XDDFOfPieChartData;

public final class ChartUtils {

    public static List getChartSeries(XWPFChart chart) {
        List series = new LinkedList<>();
        List chartSeries = chart.getChartSeries();
        series.addAll(chartSeries);
        CTPlotArea plotArea = chart.getCTChart().getPlotArea();
        for (int i = 0; i < plotArea.sizeOfOfPieChartArray(); i++) {
            CTOfPieChart barChart = plotArea.getOfPieChartArray(i);
            series.add(new XDDFOfPieChartData(chart, barChart));
        }
        return series;
    }
    
    public static Map getValueAxes(XWPFChart chart) {
        CTPlotArea plotArea = chart.getCTChart().getPlotArea();
        int sizeOfArray = plotArea.sizeOfValAxArray();
        Map axes = new HashMap<>(sizeOfArray);
        for (int i = 0; i < sizeOfArray; i++) {
            CTValAx values = plotArea.getValAxArray(i);
            axes.put(values.getAxId().getVal(), new XDDFValueAxis(values));
        }
        return axes;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy