]> source.dussan.org Git - poi.git/commitdiff
Bug 57362: Properly initialize chart axis when loading a workbook which already conta...
authorDominik Stadler <centic@apache.org>
Mon, 22 Dec 2014 14:16:23 +0000 (14:16 +0000)
committerDominik Stadler <centic@apache.org>
Mon, 22 Dec 2014 14:16:23 +0000 (14:16 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1647317 13f79535-47bb-0310-9956-ffa450edef68

src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFChart.java
src/ooxml/testcases/org/apache/poi/xssf/usermodel/charts/TestXSSFChartAxis.java
test-data/spreadsheet/57362.xlsx [new file with mode: 0644]

index 41038114f6b0f7379e39f19284bb3e4f63ce6d6e..0f2179a9dc5a1c72aca9dbe62b692f6b537504c2 100644 (file)
@@ -79,14 +79,13 @@ public final class XSSFChart extends POIXMLDocumentPart implements Chart, ChartA
         */
        private CTChart chart;
 
-       List<XSSFChartAxis> axis;
+       List<XSSFChartAxis> axis = new ArrayList<XSSFChartAxis>();
 
        /**
         * Create a new SpreadsheetML chart
         */
        protected XSSFChart() {
                super();
-               axis = new ArrayList<XSSFChartAxis>();
                createChart();
        }
 
@@ -227,13 +226,13 @@ public final class XSSFChart extends POIXMLDocumentPart implements Chart, ChartA
                return categoryAxis;
        }
 
-       public List<? extends XSSFChartAxis> getAxis() {
-               if (axis.isEmpty() && hasAxis()) {
-                       parseAxis();
-               }
-               return axis;
-       }
-
+    public List<? extends XSSFChartAxis> getAxis() {
+        if (axis.isEmpty() && hasAxis()) {
+            parseAxis();
+        }
+        return axis;
+    }
+       
        public XSSFManualLayout getManualLayout() {
                return new XSSFManualLayout(this);
        }
index 0188c7155506739c9fa175432fc99386417799b4..f1351f18620c36e2ea513bd2f446d35a690448cb 100644 (file)
 
 package org.apache.poi.xssf.usermodel.charts;
 
+import java.util.List;
+
 import junit.framework.TestCase;
 
+import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.poi.ss.usermodel.Workbook;
 import org.apache.poi.ss.usermodel.charts.*;
+import org.apache.poi.xssf.XSSFTestDataSamples;
 import org.apache.poi.xssf.usermodel.*;
 
 public final class TestXSSFChartAxis extends TestCase {
@@ -111,4 +116,21 @@ public final class TestXSSFChartAxis extends TestCase {
                axis.setMinorTickMark(AxisTickMark.CROSS);
                assertEquals(AxisTickMark.CROSS, axis.getMinorTickMark());
        }
+
+       public void testGetChartAxisBug57362() {
+         //Load existing excel with some chart on it having primary and secondary axis.
+           final Workbook workbook = XSSFTestDataSamples.openSampleWorkbook("57362.xlsx");
+        final Sheet sh = workbook.getSheetAt(0);
+        final XSSFSheet xsh = (XSSFSheet) sh;
+        final XSSFDrawing drawing = xsh.createDrawingPatriarch();
+        final XSSFChart chart = drawing.getCharts().get(0);
+
+        final List<? extends XSSFChartAxis> axisList = chart.getAxis();
+
+        assertEquals(4, axisList.size());
+        assertNotNull(axisList.get(0));
+        assertNotNull(axisList.get(1));
+        assertNotNull(axisList.get(2));
+        assertNotNull(axisList.get(3));
+       }
 }
diff --git a/test-data/spreadsheet/57362.xlsx b/test-data/spreadsheet/57362.xlsx
new file mode 100644 (file)
index 0000000..ec2be38
Binary files /dev/null and b/test-data/spreadsheet/57362.xlsx differ