Search in sources :

Example 1 with LineChartSeries

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

the class TestXSSFLineChartData 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().createCategoryAxis(AxisPosition.BOTTOM);
    ChartAxis leftAxis = chart.getChartAxisFactory().createValueAxis(AxisPosition.LEFT);
    LineChartData lineChartData = chart.getChartDataFactory().createLineChartData();
    ChartDataSource<String> xs = DataSources.fromStringCellRange(sheet, CellRangeAddress.valueOf("A1:J1"));
    ChartDataSource<Number> ys = DataSources.fromNumericCellRange(sheet, CellRangeAddress.valueOf("A2:J2"));
    LineChartSeries series = lineChartData.addSeries(xs, ys);
    assertNotNull(series);
    assertEquals(1, lineChartData.getSeries().size());
    assertTrue(lineChartData.getSeries().contains(series));
    chart.plot(lineChartData, bottomAxis, leftAxis);
    wb.close();
}
Also used : SheetBuilder(org.apache.poi.ss.util.SheetBuilder) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) Workbook(org.apache.poi.ss.usermodel.Workbook) ClientAnchor(org.apache.poi.ss.usermodel.ClientAnchor) ChartAxis(org.apache.poi.ss.usermodel.charts.ChartAxis) LineChartData(org.apache.poi.ss.usermodel.charts.LineChartData) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) Sheet(org.apache.poi.ss.usermodel.Sheet) LineChartSeries(org.apache.poi.ss.usermodel.charts.LineChartSeries) Chart(org.apache.poi.ss.usermodel.Chart) Test(org.junit.Test)

Example 2 with LineChartSeries

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

the class XSSFLineChartData method addSeries.

public LineChartSeries addSeries(ChartDataSource<?> categoryAxisData, ChartDataSource<? extends Number> values) {
    if (!values.isNumeric()) {
        throw new IllegalArgumentException("Value data source must be numeric.");
    }
    int numOfSeries = series.size();
    Series newSeries = new Series(numOfSeries, numOfSeries, categoryAxisData, values);
    series.add(newSeries);
    return newSeries;
}
Also used : LineChartSeries(org.apache.poi.ss.usermodel.charts.LineChartSeries)

Aggregations

LineChartSeries (org.apache.poi.ss.usermodel.charts.LineChartSeries)2 Chart (org.apache.poi.ss.usermodel.Chart)1 ClientAnchor (org.apache.poi.ss.usermodel.ClientAnchor)1 Sheet (org.apache.poi.ss.usermodel.Sheet)1 Workbook (org.apache.poi.ss.usermodel.Workbook)1 ChartAxis (org.apache.poi.ss.usermodel.charts.ChartAxis)1 LineChartData (org.apache.poi.ss.usermodel.charts.LineChartData)1 SheetBuilder (org.apache.poi.ss.util.SheetBuilder)1 XSSFWorkbook (org.apache.poi.xssf.usermodel.XSSFWorkbook)1 Test (org.junit.Test)1