Search in sources :

Example 16 with ChartAxis

use of org.apache.poi.ss.usermodel.charts.ChartAxis in project ocvn by devgateway.

the class ExcelChartDefault method createWorkbook.

@Override
public Workbook createWorkbook() {
    final ExcelChartSheet excelChartSheet = new ExcelChartSheetDefault(workbook, type.toString());
    final Chart chart = excelChartSheet.createChartAndLegend();
    addCategories(excelChartSheet);
    addValues(excelChartSheet);
    final CustomChartDataFactory customChartDataFactory = new CustomChartDataFactoryDefault();
    final CustomChartData chartData = customChartDataFactory.createChartData(type, title);
    final ChartDataSource<?> categoryDataSource = excelChartSheet.getCategoryChartDataSource();
    final List<ChartDataSource<Number>> valuesDataSource = excelChartSheet.getValuesChartDataSource();
    for (int i = 0; i < valuesDataSource.size(); i++) {
        final ChartDataSource<Number> valueDataSource = valuesDataSource.get(i);
        if (seriesTitle.isEmpty()) {
            chartData.addSeries(categoryDataSource, valueDataSource);
        } else {
            chartData.addSeries(seriesTitle.get(i), categoryDataSource, valueDataSource);
        }
    }
    // we don't have any axis for a pie chart
    if (type.equals(ChartType.pie)) {
        chart.plot(chartData);
    } else {
        // Use a category axis for the bottom axis.
        final ChartAxis bottomAxis = chart.getChartAxisFactory().createCategoryAxis(AxisPosition.BOTTOM);
        final ValueAxis leftAxis = chart.getChartAxisFactory().createValueAxis(AxisPosition.LEFT);
        leftAxis.setCrosses(AxisCrosses.AUTO_ZERO);
        chart.plot(chartData, bottomAxis, leftAxis);
    }
    return workbook;
}
Also used : ChartDataSource(org.apache.poi.ss.usermodel.charts.ChartDataSource) CustomChartDataFactory(org.devgateway.toolkit.web.excelcharts.util.CustomChartDataFactory) CustomChartDataFactoryDefault(org.devgateway.toolkit.web.excelcharts.util.CustomChartDataFactoryDefault) ChartAxis(org.apache.poi.ss.usermodel.charts.ChartAxis) ValueAxis(org.apache.poi.ss.usermodel.charts.ValueAxis) Chart(org.apache.poi.ss.usermodel.Chart)

Example 17 with ChartAxis

use of org.apache.poi.ss.usermodel.charts.ChartAxis in project ocvn by devgateway.

the class XSSFBarChartData method fillChart.

@Override
public void fillChart(final Chart chart, final ChartAxis... axis) {
    if (!(chart instanceof XSSFChart)) {
        throw new IllegalArgumentException("Chart must be instance of XSSFChart");
    }
    final XSSFChart xssfChart = (XSSFChart) chart;
    final CTPlotArea plotArea = xssfChart.getCTChart().getPlotArea();
    final CTBarChart barChart = plotArea.addNewBarChart();
    barChart.addNewVaryColors().setVal(false);
    // set bars orientation
    barChart.addNewBarDir().setVal(barDir);
    xssfChart.setTitle(this.title);
    CTValAx[] ctValAx = plotArea.getValAxArray();
    if (ctValAx.length != 0) {
        ctValAx[0].addNewMajorGridlines().addNewSpPr().addNewSolidFill();
        ctValAx[0].getCrossBetween().setVal(STCrossBetween.BETWEEN);
    }
    for (CustomChartSeries s : series) {
        s.addToChart(barChart);
    }
    for (ChartAxis ax : axis) {
        barChart.addNewAxId().setVal(ax.getId());
    }
}
Also used : XSSFChart(org.apache.poi.xssf.usermodel.XSSFChart) CTValAx(org.openxmlformats.schemas.drawingml.x2006.chart.CTValAx) CustomChartSeries(org.devgateway.toolkit.web.excelcharts.CustomChartSeries) ChartAxis(org.apache.poi.ss.usermodel.charts.ChartAxis) CTPlotArea(org.openxmlformats.schemas.drawingml.x2006.chart.CTPlotArea) CTBarChart(org.openxmlformats.schemas.drawingml.x2006.chart.CTBarChart)

Example 18 with ChartAxis

use of org.apache.poi.ss.usermodel.charts.ChartAxis in project ocvn by devgateway.

the class XSSFBubbleChartData method fillChart.

@Override
public void fillChart(final Chart chart, final ChartAxis... axis) {
    if (!(chart instanceof XSSFChart)) {
        throw new IllegalArgumentException("Chart must be instance of XSSFChart");
    }
    final XSSFChart xssfChart = (XSSFChart) chart;
    final CTPlotArea plotArea = xssfChart.getCTChart().getPlotArea();
    final CTBubbleChart bubbleChart = plotArea.addNewBubbleChart();
    for (CustomChartSeries s : series) {
        s.addToChart(bubbleChart);
    }
    for (ChartAxis ax : axis) {
        bubbleChart.addNewAxId().setVal(ax.getId());
    }
    xssfChart.setTitle(this.title);
}
Also used : XSSFChart(org.apache.poi.xssf.usermodel.XSSFChart) CustomChartSeries(org.devgateway.toolkit.web.excelcharts.CustomChartSeries) ChartAxis(org.apache.poi.ss.usermodel.charts.ChartAxis) CTPlotArea(org.openxmlformats.schemas.drawingml.x2006.chart.CTPlotArea) CTBubbleChart(org.openxmlformats.schemas.drawingml.x2006.chart.CTBubbleChart)

Example 19 with ChartAxis

use of org.apache.poi.ss.usermodel.charts.ChartAxis in project oc-explorer by devgateway.

the class ExcelChartDefault method createWorkbook.

@Override
public Workbook createWorkbook() {
    final ExcelChartSheet excelChartSheet = new ExcelChartSheetDefault(workbook, type.toString());
    final Chart chart = excelChartSheet.createChartAndLegend();
    addCategories(excelChartSheet);
    addValues(excelChartSheet);
    final CustomChartDataFactory customChartDataFactory = new CustomChartDataFactoryDefault();
    final CustomChartData chartData = customChartDataFactory.createChartData(type, title);
    final ChartDataSource<?> categoryDataSource = excelChartSheet.getCategoryChartDataSource();
    final List<ChartDataSource<Number>> valuesDataSource = excelChartSheet.getValuesChartDataSource();
    for (int i = 0; i < valuesDataSource.size(); i++) {
        final ChartDataSource<Number> valueDataSource = valuesDataSource.get(i);
        if (seriesTitle.isEmpty()) {
            chartData.addSeries(categoryDataSource, valueDataSource);
        } else {
            chartData.addSeries(seriesTitle.get(i), categoryDataSource, valueDataSource);
        }
    }
    // we don't have any axis for a pie chart
    if (type.equals(ChartType.pie)) {
        chart.plot(chartData);
    } else {
        // Use a category axis for the bottom axis.
        final ChartAxis bottomAxis = chart.getChartAxisFactory().createCategoryAxis(AxisPosition.BOTTOM);
        final ValueAxis leftAxis = chart.getChartAxisFactory().createValueAxis(AxisPosition.LEFT);
        leftAxis.setCrosses(AxisCrosses.AUTO_ZERO);
        chart.plot(chartData, bottomAxis, leftAxis);
    }
    return workbook;
}
Also used : ChartDataSource(org.apache.poi.ss.usermodel.charts.ChartDataSource) CustomChartDataFactory(org.devgateway.toolkit.web.excelcharts.util.CustomChartDataFactory) CustomChartDataFactoryDefault(org.devgateway.toolkit.web.excelcharts.util.CustomChartDataFactoryDefault) ChartAxis(org.apache.poi.ss.usermodel.charts.ChartAxis) ValueAxis(org.apache.poi.ss.usermodel.charts.ValueAxis) Chart(org.apache.poi.ss.usermodel.Chart)

Example 20 with ChartAxis

use of org.apache.poi.ss.usermodel.charts.ChartAxis in project oc-explorer by devgateway.

the class XSSFAreaChartData method fillChart.

@Override
public void fillChart(final Chart chart, final ChartAxis... axis) {
    if (!(chart instanceof XSSFChart)) {
        throw new IllegalArgumentException("Chart must be instance of XSSFChart");
    }
    final XSSFChart xssfChart = (XSSFChart) chart;
    final CTPlotArea plotArea = xssfChart.getCTChart().getPlotArea();
    final CTAreaChart areChart = plotArea.addNewAreaChart();
    areChart.addNewVaryColors().setVal(false);
    xssfChart.setTitleText(this.title);
    CTValAx[] ctValAx = plotArea.getValAxArray();
    if (ctValAx.length != 0) {
        ctValAx[0].addNewMajorGridlines().addNewSpPr().addNewSolidFill();
        ctValAx[0].getCrossBetween().setVal(STCrossBetween.BETWEEN);
    }
    for (CustomChartSeries s : series) {
        s.addToChart(areChart);
    }
    for (ChartAxis ax : axis) {
        areChart.addNewAxId().setVal(ax.getId());
    }
}
Also used : XSSFChart(org.apache.poi.xssf.usermodel.XSSFChart) CTValAx(org.openxmlformats.schemas.drawingml.x2006.chart.CTValAx) CustomChartSeries(org.devgateway.toolkit.web.excelcharts.CustomChartSeries) ChartAxis(org.apache.poi.ss.usermodel.charts.ChartAxis) CTAreaChart(org.openxmlformats.schemas.drawingml.x2006.chart.CTAreaChart) CTPlotArea(org.openxmlformats.schemas.drawingml.x2006.chart.CTPlotArea)

Aggregations

ChartAxis (org.apache.poi.ss.usermodel.charts.ChartAxis)25 XSSFChart (org.apache.poi.xssf.usermodel.XSSFChart)18 CTPlotArea (org.openxmlformats.schemas.drawingml.x2006.chart.CTPlotArea)16 CustomChartSeries (org.devgateway.toolkit.web.excelcharts.CustomChartSeries)12 CTValAx (org.openxmlformats.schemas.drawingml.x2006.chart.CTValAx)10 Chart (org.apache.poi.ss.usermodel.Chart)9 ValueAxis (org.apache.poi.ss.usermodel.charts.ValueAxis)6 ClientAnchor (org.apache.poi.ss.usermodel.ClientAnchor)5 Row (org.apache.poi.ss.usermodel.Row)5 Sheet (org.apache.poi.ss.usermodel.Sheet)5 LineChartData (org.apache.poi.ss.usermodel.charts.LineChartData)5 CellRangeAddress (org.apache.poi.ss.util.CellRangeAddress)5 Cell (org.apache.poi.ss.usermodel.Cell)4 Workbook (org.apache.poi.ss.usermodel.Workbook)4 XSSFWorkbook (org.apache.poi.xssf.usermodel.XSSFWorkbook)4 CTCatAx (org.openxmlformats.schemas.drawingml.x2006.chart.CTCatAx)4 AddTrace (com.google.firebase.perf.metrics.AddTrace)3 SpreadsheetUtils.getCellRangeAddress (com.supercilex.robotscouter.data.client.spreadsheet.SpreadsheetUtils.getCellRangeAddress)3 SpreadsheetUtils.getMetricForChart (com.supercilex.robotscouter.data.client.spreadsheet.SpreadsheetUtils.getMetricForChart)3 PreferencesUtilsKt.setShouldShowExportHint (com.supercilex.robotscouter.util.PreferencesUtilsKt.setShouldShowExportHint)3