You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ab...@apache.org on 2019/05/29 01:05:26 UTC
svn commit: r1860311 - in /poi/trunk/src:
examples/src/org/apache/poi/xssf/usermodel/examples/ExcelChartWithTargetLine.java
ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFChart.java
Author: abearez
Date: Wed May 29 01:05:26 2019
New Revision: 1860311
URL: http://svn.apache.org/viewvc?rev=1860311&view=rev
Log:
remove code smells
Modified:
poi/trunk/src/examples/src/org/apache/poi/xssf/usermodel/examples/ExcelChartWithTargetLine.java
poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFChart.java
Modified: poi/trunk/src/examples/src/org/apache/poi/xssf/usermodel/examples/ExcelChartWithTargetLine.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/examples/src/org/apache/poi/xssf/usermodel/examples/ExcelChartWithTargetLine.java?rev=1860311&r1=1860310&r2=1860311&view=diff
==============================================================================
--- poi/trunk/src/examples/src/org/apache/poi/xssf/usermodel/examples/ExcelChartWithTargetLine.java (original)
+++ poi/trunk/src/examples/src/org/apache/poi/xssf/usermodel/examples/ExcelChartWithTargetLine.java Wed May 29 01:05:26 2019
@@ -183,48 +183,51 @@ class ExcelChartWithTargetLine {
barCategories.getOrAddShapeProperties().setLineProperties(categoriesProps);
}
- public static void main(String[] args) throws Exception {
-
- XSSFWorkbook workbook = new XSSFWorkbook();
- XSSFSheet sheet = workbook.createSheet("targetline");
- final int NUM_OF_COLUMNS = 4;
-
- // create some data
- XSSFRow row;
- XSSFCell cell;
- String[] headings = new String[] { "Year", "Male", "Female", "Other" };
- int rowIndex = 0;
- row = sheet.createRow(rowIndex);
- for (int colIndex = 0; colIndex < NUM_OF_COLUMNS; colIndex++) {
- cell = row.createCell(colIndex);
- cell.setCellValue(headings[colIndex]);
+ private static XSSFClientAnchor createAnchor(XSSFDrawing drawing, int[] chartedCols) {
+ if (chartedCols.length > 1) {
+ return drawing.createAnchor(0, 0, 0, 0, 0, 8, 10, 23);
+ } else {
+ return drawing.createAnchor(0, 0, 0, 0, 0, 8, 5, 23);
}
- double[][] values = new double[][] { new double[] { 1980, 56.0, 44.1, 12.2 },
- new double[] { 1985, 34.5, 41.0, 4 }, new double[] { 1990, 65.0, 68.5, 9.1 },
- new double[] { 1995, 34.7, 47.6, 4.9 }, new double[] { 2000, 23.0, 64.5, 11.1 },
- new double[] { 2005, 56.3, 69.8, 9.5 } };
- for (; rowIndex < NUM_OF_ROWS; rowIndex++) {
- row = sheet.createRow(rowIndex + 1);
+ }
+
+ public static void main(String[] args) throws Exception {
+ try (XSSFWorkbook workbook = new XSSFWorkbook()) {
+ XSSFSheet sheet = workbook.createSheet("targetline");
+ final int NUM_OF_COLUMNS = 4;
+
+ // create some data
+ XSSFRow row;
+ XSSFCell cell;
+ String[] headings = new String[] { "Year", "Male", "Female", "Other" };
+ int rowIndex = 0;
+ row = sheet.createRow(rowIndex);
for (int colIndex = 0; colIndex < NUM_OF_COLUMNS; colIndex++) {
cell = row.createCell(colIndex);
- cell.setCellValue(values[rowIndex][colIndex]);
+ cell.setCellValue(headings[colIndex]);
+ }
+ double[][] values = new double[][] { new double[] { 1980, 56.0, 44.1, 12.2 },
+ new double[] { 1985, 34.5, 41.0, 4 }, new double[] { 1990, 65.0, 68.5, 9.1 },
+ new double[] { 1995, 34.7, 47.6, 4.9 }, new double[] { 2000, 23.0, 64.5, 11.1 },
+ new double[] { 2005, 56.3, 69.8, 9.5 } };
+ for (; rowIndex < NUM_OF_ROWS; rowIndex++) {
+ row = sheet.createRow(rowIndex + 1);
+ for (int colIndex = 0; colIndex < NUM_OF_COLUMNS; colIndex++) {
+ cell = row.createCell(colIndex);
+ cell.setCellValue(values[rowIndex][colIndex]);
+ }
}
- }
- int[] chartedCols = new int[] { 1, 2 , 3 };
+ int[] chartedCols = new int[] { 1, 2 , 3 };
- XSSFDrawing drawing = sheet.createDrawingPatriarch();
- XSSFClientAnchor anchor = null;
- if (chartedCols.length > 1) {
- anchor = drawing.createAnchor(0, 0, 0, 0, 0, 8, 10, 23);
- } else {
- anchor = drawing.createAnchor(0, 0, 0, 0, 0, 8, 5, 23);
- }
- XSSFChart chart = drawing.createChart(anchor);
- createChart(chart, sheet, chartedCols, 42.0);
-
- workbook.write(new FileOutputStream("ExcelChartWithTargetLine.xlsx"));
- workbook.close();
+ XSSFDrawing drawing = sheet.createDrawingPatriarch();
+ XSSFClientAnchor anchor = createAnchor(drawing, chartedCols);
+ XSSFChart chart = drawing.createChart(anchor);
+ createChart(chart, sheet, chartedCols, 42.0);
+ try (FileOutputStream fos = new FileOutputStream("ExcelChartWithTargetLine.xlsx")) {
+ workbook.write(fos);
+ }
+ }
}
}
Modified: poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFChart.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFChart.java?rev=1860311&r1=1860310&r2=1860311&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFChart.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFChart.java Wed May 29 01:05:26 2019
@@ -588,6 +588,7 @@ public abstract class XDDFChart extends
return new XDDFSurfaceChartData(this, plotArea.addNewSurfaceChart(), categories, mapValues);
case SURFACE3D:
return new XDDFSurface3DChartData(this, plotArea.addNewSurface3DChart(), categories, mapValues);
+ // TODO repeat above code for missing charts: Bubble, Doughnut, OfPie and Stock
default:
return null;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org