19 package org.sleuthkit.autopsy.datasourcesummary.uiutils;
21 import java.lang.reflect.Constructor;
22 import java.lang.reflect.InvocationTargetException;
23 import java.util.Arrays;
24 import java.util.List;
25 import org.apache.poi.ss.usermodel.Sheet;
26 import org.apache.poi.ss.util.CellRangeAddress;
27 import org.apache.poi.xddf.usermodel.chart.LegendPosition;
28 import org.apache.poi.xddf.usermodel.chart.XDDFChartLegend;
29 import org.apache.poi.xddf.usermodel.chart.XDDFDataSource;
30 import org.apache.poi.xddf.usermodel.chart.XDDFDataSourcesFactory;
31 import org.apache.poi.xddf.usermodel.chart.XDDFNumericalDataSource;
32 import org.apache.poi.xddf.usermodel.chart.XDDFPieChartData;
33 import org.apache.poi.xssf.usermodel.XSSFChart;
34 import org.apache.poi.xssf.usermodel.XSSFClientAnchor;
35 import org.apache.poi.xssf.usermodel.XSSFDrawing;
36 import org.apache.poi.xssf.usermodel.XSSFSheet;
37 import org.openxmlformats.schemas.drawingml.x2006.chart.CTPieChart;
73 String valueColumnHeader, String valueFormatString,
75 List<PieChartItem> slices) {
97 String valueColumnHeader, String valueFormatString,
98 String chartTitle, String sheetName,
99 List<PieChartItem> slices,
100 int colOffset,
int rowPadding,
int colSize,
int rowSize) {
123 write(sheet, 0, 0, env);
128 if (!(sheet instanceof XSSFSheet)) {
129 throw new ExcelExportException(
"Sheet must be an XSSFSheet in order to write.");
132 XSSFSheet xssfSheet = (XSSFSheet) sheet;
135 ItemDimensions tableDimensions = tableExport.
write(xssfSheet, rowStart + rowPadding, colStart, env);
137 XSSFDrawing drawing = xssfSheet.createDrawingPatriarch();
139 int chartColStart = colStart + 2 +
colOffset;
142 XSSFClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, chartColStart, rowStart + rowPadding, chartColStart + colSize + 1, rowStart + rowSize + 1);
144 XSSFChart chart = drawing.createChart(anchor);
145 chart.setTitleText(chartTitle);
146 chart.setTitleOverlay(
false);
147 XDDFChartLegend legend = chart.getOrAddLegend();
148 legend.setPosition(LegendPosition.RIGHT);
151 XDDFDataSource<String> cat = XDDFDataSourcesFactory.fromStringCellRange(xssfSheet,
155 XDDFNumericalDataSource<Double> val = XDDFDataSourcesFactory.fromNumericCellRange(xssfSheet,
167 XDDFPieChartData data;
169 Constructor<XDDFPieChartData> constructor = XDDFPieChartData.class.getConstructor(CTPieChart.class);
170 constructor.setAccessible(
true);
171 data = constructor.newInstance(chart.getCTChart().getPlotArea().addNewPieChart());
172 }
catch (NoSuchMethodException | InvocationTargetException | InstantiationException | IllegalAccessException | IllegalArgumentException ex) {
173 throw new ExcelExportException(
"Error while instantiating chart data.", ex);
176 data.setVaryColors(
true);
177 data.addSeries(cat, val);
180 if (!chart.getCTChart().getPlotArea().getPieChartArray(0).getSerArray(0).isSetDLbls()) {
181 chart.getCTChart().getPlotArea().getPieChartArray(0).getSerArray(0).addNewDLbls();
184 chart.getCTChart().getPlotArea().getPieChartArray(0).getSerArray(0).getDLbls().addNewShowVal().setVal(
true);
185 chart.getCTChart().getPlotArea().getPieChartArray(0).getSerArray(0).getDLbls().addNewShowSerName().setVal(
false);
186 chart.getCTChart().getPlotArea().getPieChartArray(0).getSerArray(0).getDLbls().addNewShowCatName().setVal(
true);
187 chart.getCTChart().getPlotArea().getPieChartArray(0).getSerArray(0).getDLbls().addNewShowPercent().setVal(
true);
188 chart.getCTChart().getPlotArea().getPieChartArray(0).getSerArray(0).getDLbls().addNewShowLegendKey().setVal(
false);
static final int DEFAULT_COL_SIZE
PieChartExport(String keyColumnHeader, String valueColumnHeader, String valueFormatString, String chartTitle, List< PieChartItem > slices)
PieChartExport(String keyColumnHeader, String valueColumnHeader, String valueFormatString, String chartTitle, String sheetName, List< PieChartItem > slices, int colOffset, int rowPadding, int colSize, int rowSize)
static final int DEFAULT_ROW_SIZE
static final int DEFAULT_COL_OFFSET
ItemDimensions write(Sheet sheet, int rowStart, int colStart, ExcelExport.WorksheetEnv env)
static final int DEFAULT_ROW_PADDING
ItemDimensions write(Sheet sheet, int rowStart, int colStart, ExcelExport.WorksheetEnv env)
void renderSheet(Sheet sheet, ExcelExport.WorksheetEnv env)
final ExcelTableExport< PieChartItem,?extends ExcelCellModel > tableExport