use of org.apache.poi.xssf.usermodel.XSSFChart in project poi by apache.
the class TestXSSFChartTitle method testNewChart.
@Test
public void testNewChart() throws IOException {
Workbook wb = createWorkbookWithChart();
XSSFChart chart = getChartFromWorkbook(wb, "linechart");
assertNotNull(chart);
assertNull(chart.getTitleText());
final String myTitle = "My chart title";
chart.setTitleText(myTitle);
XSSFRichTextString queryTitle = chart.getTitleText();
assertNotNull(queryTitle);
assertEquals(myTitle, queryTitle.toString());
final String myTitleFormula = "1 & \" and \" & 2";
chart.setTitleFormula(myTitleFormula);
// setting formula should unset text, but since there is a formula, returns an empty string
assertEquals("", chart.getTitleText().toString());
String titleFormula = chart.getTitleFormula();
assertNotNull(titleFormula);
assertEquals(myTitleFormula, titleFormula);
wb.close();
}
use of org.apache.poi.xssf.usermodel.XSSFChart 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());
}
}
use of org.apache.poi.xssf.usermodel.XSSFChart 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);
}
use of org.apache.poi.xssf.usermodel.XSSFChart in project ocvn by devgateway.
the class XSSFPieChartData 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 CTPieChart pieChart = plotArea.addNewPieChart();
pieChart.addNewVaryColors().setVal(true);
xssfChart.setTitle(this.title);
for (CustomChartSeries s : series) {
s.addToChart(pieChart);
}
}
use of org.apache.poi.xssf.usermodel.XSSFChart in project ocvn by devgateway.
the class TotalCancelledTendersExcelControllerTest method cancelledFundingExcelChart.
@Test
public void cancelledFundingExcelChart() throws Exception {
LangYearFilterPagingRequest filter = getLangYearFilterMockRequest();
totalCancelledTendersExcelController.cancelledFundingExcelChart(filter, mockHttpServletResponse);
final byte[] responseOutput = mockHttpServletResponse.getContentAsByteArray();
final Workbook workbook = new XSSFWorkbook(new ByteArrayInputStream(responseOutput));
Assert.assertNotNull(workbook);
final Sheet sheet = workbook.getSheet(ChartType.area.toString());
Assert.assertNotNull("check chart type, sheet name should be the same as the type", sheet);
final XSSFDrawing drawing = (XSSFDrawing) sheet.getDrawingPatriarch();
final List<XSSFChart> charts = drawing.getCharts();
Assert.assertEquals("number of charts", 1, charts.size());
final XSSFChart chart = charts.get(0);
Assert.assertEquals("chart title", translationService.getValue(filter.getLanguage(), "charts:cancelledAmounts:title"), chart.getTitle().getString());
final List<? extends XSSFChartAxis> axis = chart.getAxis();
Assert.assertEquals("number of axis", 2, axis.size());
final CTChart ctChart = chart.getCTChart();
Assert.assertEquals("Check if we have 1 area chart", 1, ctChart.getPlotArea().getAreaChartArray().length);
}
Aggregations