Search in sources :

Example 11 with ChartAxis

use of org.apache.poi.ss.usermodel.charts.ChartAxis in project ocvn 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.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(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)

Example 12 with ChartAxis

use of org.apache.poi.ss.usermodel.charts.ChartAxis in project Robot-Scouter by SUPERCILEX.

the class SpreadsheetExporter method buildTeamChart.

@AddTrace(name = "buildTeamChart")
private void buildTeamChart(Row row, TeamHelper teamHelper, Map<Chart, Pair<LineChartData, List<ChartAxis>>> chartData, Map<Metric<Void>, Chart> chartPool) {
    if (isUnsupportedDevice())
        return;
    Sheet sheet = row.getSheet();
    int rowNum = row.getRowNum();
    int lastDataCellNum = row.getSheet().getRow(0).getLastCellNum() - 2;
    Chart chart = null;
    Pair<Integer, Metric<Void>> nearestHeader = null;
    List<Row> rows = getAdjustedList(row.getSheet());
    for (int i = row.getRowNum() - 1; i >= 0; i--) {
        Metric metric = getMetricForScouts(mScouts.get(teamHelper), mCache.getMetricKey(rows.get(i)));
        if (metric.getType() == HEADER) {
            nearestHeader = Pair.create(i, metric);
            Chart cachedChart = chartPool.get(metric);
            if (cachedChart != null)
                chart = cachedChart;
            break;
        }
    }
    chartFinder: if (nearestHeader == null) {
        for (Chart possibleChart : chartData.keySet()) {
            if (possibleChart instanceof XSSFChart) {
                XSSFChart xChart = (XSSFChart) possibleChart;
                if (xChart.getGraphicFrame().getAnchor().getRow1() == SINGLE_ITEM) {
                    nearestHeader = Pair.create(0, getMetricForChart(xChart, chartPool));
                    chart = xChart;
                    break chartFinder;
                }
            }
        }
        nearestHeader = Pair.create(0, new Metric.Header("", null));
    }
    LineChartData data;
    if (chart == null) {
        Drawing drawing = sheet.createDrawingPatriarch();
        Integer headerIndex = nearestHeader.first + 1;
        int startChartIndex = lastDataCellNum + 3;
        chart = drawing.createChart(createChartAnchor(drawing, getChartRowIndex(headerIndex, new ArrayList<>(chartData.keySet())), startChartIndex, startChartIndex + 10));
        LineChartData lineChartData = chart.getChartDataFactory().createLineChartData();
        data = lineChartData;
        ChartAxis bottomAxis = chart.getChartAxisFactory().createCategoryAxis(AxisPosition.BOTTOM);
        ValueAxis leftAxis = chart.getChartAxisFactory().createValueAxis(AxisPosition.LEFT);
        leftAxis.setCrosses(AxisCrosses.AUTO_ZERO);
        ChartLegend legend = chart.getOrCreateLegend();
        legend.setPosition(LegendPosition.RIGHT);
        chartData.put(chart, Pair.create(lineChartData, Arrays.asList(bottomAxis, leftAxis)));
        chartPool.put(nearestHeader.second, chart);
    } else {
        data = chartData.get(chart).first;
    }
    ChartDataSource<String> categorySource = DataSources.fromStringCellRange(sheet, new CellRangeAddress(0, 0, 1, lastDataCellNum));
    data.addSeries(categorySource, DataSources.fromNumericCellRange(sheet, new CellRangeAddress(rowNum, rowNum, 1, lastDataCellNum))).setTitle(row.getCell(0).getStringCellValue());
}
Also used : Drawing(org.apache.poi.ss.usermodel.Drawing) ArrayList(java.util.ArrayList) RichTextString(org.apache.poi.ss.usermodel.RichTextString) ChartLegend(org.apache.poi.ss.usermodel.charts.ChartLegend) PreferencesUtilsKt.setShouldShowExportHint(com.supercilex.robotscouter.util.PreferencesUtilsKt.setShouldShowExportHint) PreferencesUtilsKt.shouldShowExportHint(com.supercilex.robotscouter.util.PreferencesUtilsKt.shouldShowExportHint) XSSFChart(org.apache.poi.xssf.usermodel.XSSFChart) ChartAxis(org.apache.poi.ss.usermodel.charts.ChartAxis) ValueAxis(org.apache.poi.ss.usermodel.charts.ValueAxis) LineChartData(org.apache.poi.ss.usermodel.charts.LineChartData) Metric(com.supercilex.robotscouter.data.model.Metric) Row(org.apache.poi.ss.usermodel.Row) CellRangeAddress(org.apache.poi.ss.util.CellRangeAddress) SpreadsheetUtils.getCellRangeAddress(com.supercilex.robotscouter.data.client.spreadsheet.SpreadsheetUtils.getCellRangeAddress) Sheet(org.apache.poi.ss.usermodel.Sheet) XSSFChart(org.apache.poi.xssf.usermodel.XSSFChart) Chart(org.apache.poi.ss.usermodel.Chart) CTChart(org.openxmlformats.schemas.drawingml.x2006.chart.CTChart) SpreadsheetUtils.getMetricForChart(com.supercilex.robotscouter.data.client.spreadsheet.SpreadsheetUtils.getMetricForChart) AddTrace(com.google.firebase.perf.metrics.AddTrace)

Example 13 with ChartAxis

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

the class XSSFChart method createCategoryAxis.

public XSSFCategoryAxis createCategoryAxis(AxisPosition pos) {
    long id = axis.size() + 1;
    XSSFCategoryAxis categoryAxis = new XSSFCategoryAxis(this, id, pos);
    if (axis.size() == 1) {
        ChartAxis ax = axis.get(0);
        ax.crossAxis(categoryAxis);
        categoryAxis.crossAxis(ax);
    }
    axis.add(categoryAxis);
    return categoryAxis;
}
Also used : XSSFCategoryAxis(org.apache.poi.xssf.usermodel.charts.XSSFCategoryAxis) XSSFChartAxis(org.apache.poi.xssf.usermodel.charts.XSSFChartAxis) ChartAxis(org.apache.poi.ss.usermodel.charts.ChartAxis)

Example 14 with ChartAxis

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

the class XSSFChart method createValueAxis.

public XSSFValueAxis createValueAxis(AxisPosition pos) {
    long id = axis.size() + 1;
    XSSFValueAxis valueAxis = new XSSFValueAxis(this, id, pos);
    if (axis.size() == 1) {
        ChartAxis ax = axis.get(0);
        ax.crossAxis(valueAxis);
        valueAxis.crossAxis(ax);
    }
    axis.add(valueAxis);
    return valueAxis;
}
Also used : XSSFChartAxis(org.apache.poi.xssf.usermodel.charts.XSSFChartAxis) ChartAxis(org.apache.poi.ss.usermodel.charts.ChartAxis) XSSFValueAxis(org.apache.poi.xssf.usermodel.charts.XSSFValueAxis)

Example 15 with ChartAxis

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

the class TestXSSFScatterChartData method testOneSeriePlot.

@Test
public void testOneSeriePlot() throws IOException {
    Workbook wb = new XSSFWorkbook();
    Sheet sheet = new SheetBuilder(wb, plotData).build();
    Drawing<?> drawing = sheet.createDrawingPatriarch();
    ClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, 1, 1, 10, 30);
    Chart chart = drawing.createChart(anchor);
    ChartAxis bottomAxis = chart.getChartAxisFactory().createValueAxis(AxisPosition.BOTTOM);
    ChartAxis leftAxis = chart.getChartAxisFactory().createValueAxis(AxisPosition.LEFT);
    ScatterChartData scatterChartData = chart.getChartDataFactory().createScatterChartData();
    ChartDataSource<String> xs = DataSources.fromStringCellRange(sheet, CellRangeAddress.valueOf("A1:J1"));
    ChartDataSource<Number> ys = DataSources.fromNumericCellRange(sheet, CellRangeAddress.valueOf("A2:J2"));
    ScatterChartSeries series = scatterChartData.addSerie(xs, ys);
    assertNotNull(series);
    assertEquals(1, scatterChartData.getSeries().size());
    assertTrue(scatterChartData.getSeries().contains(series));
    chart.plot(scatterChartData, bottomAxis, leftAxis);
    wb.close();
}
Also used : SheetBuilder(org.apache.poi.ss.util.SheetBuilder) ScatterChartData(org.apache.poi.ss.usermodel.charts.ScatterChartData) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) Workbook(org.apache.poi.ss.usermodel.Workbook) ScatterChartSeries(org.apache.poi.ss.usermodel.charts.ScatterChartSeries) ClientAnchor(org.apache.poi.ss.usermodel.ClientAnchor) ChartAxis(org.apache.poi.ss.usermodel.charts.ChartAxis) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) Sheet(org.apache.poi.ss.usermodel.Sheet) Chart(org.apache.poi.ss.usermodel.Chart) Test(org.junit.Test)

Aggregations

ChartAxis (org.apache.poi.ss.usermodel.charts.ChartAxis)18 XSSFChart (org.apache.poi.xssf.usermodel.XSSFChart)12 CTPlotArea (org.openxmlformats.schemas.drawingml.x2006.chart.CTPlotArea)10 Chart (org.apache.poi.ss.usermodel.Chart)8 CustomChartSeries (org.devgateway.toolkit.web.excelcharts.CustomChartSeries)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 ValueAxis (org.apache.poi.ss.usermodel.charts.ValueAxis)5 CellRangeAddress (org.apache.poi.ss.util.CellRangeAddress)5 CTValAx (org.openxmlformats.schemas.drawingml.x2006.chart.CTValAx)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 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 PreferencesUtilsKt.shouldShowExportHint (com.supercilex.robotscouter.util.PreferencesUtilsKt.shouldShowExportHint)3