Search in sources :

Example 6 with ValueAxis

use of org.apache.poi.ss.usermodel.charts.ValueAxis 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 7 with ValueAxis

use of org.apache.poi.ss.usermodel.charts.ValueAxis 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)

Aggregations

Chart (org.apache.poi.ss.usermodel.Chart)7 ValueAxis (org.apache.poi.ss.usermodel.charts.ValueAxis)7 ChartAxis (org.apache.poi.ss.usermodel.charts.ChartAxis)6 Row (org.apache.poi.ss.usermodel.Row)5 CellRangeAddress (org.apache.poi.ss.util.CellRangeAddress)5 Cell (org.apache.poi.ss.usermodel.Cell)4 ClientAnchor (org.apache.poi.ss.usermodel.ClientAnchor)4 Sheet (org.apache.poi.ss.usermodel.Sheet)4 ChartLegend (org.apache.poi.ss.usermodel.charts.ChartLegend)4 Workbook (org.apache.poi.ss.usermodel.Workbook)3 LineChartData (org.apache.poi.ss.usermodel.charts.LineChartData)3 XSSFChart (org.apache.poi.xssf.usermodel.XSSFChart)3 XSSFWorkbook (org.apache.poi.xssf.usermodel.XSSFWorkbook)3 AddTrace (com.google.firebase.perf.metrics.AddTrace)2 SpreadsheetUtils.getCellRangeAddress (com.supercilex.robotscouter.data.client.spreadsheet.SpreadsheetUtils.getCellRangeAddress)2 SpreadsheetUtils.getMetricForChart (com.supercilex.robotscouter.data.client.spreadsheet.SpreadsheetUtils.getMetricForChart)2 PreferencesUtilsKt.setShouldShowExportHint (com.supercilex.robotscouter.util.PreferencesUtilsKt.setShouldShowExportHint)2 PreferencesUtilsKt.shouldShowExportHint (com.supercilex.robotscouter.util.PreferencesUtilsKt.shouldShowExportHint)2 FileOutputStream (java.io.FileOutputStream)2 Drawing (org.apache.poi.ss.usermodel.Drawing)2