]> source.dussan.org Git - poi.git/commitdiff
Clear all chart's properties as if newly created
authorAlain Béarez <abearez@apache.org>
Sun, 5 Jan 2020 23:54:12 +0000 (23:54 +0000)
committerAlain Béarez <abearez@apache.org>
Sun, 5 Jan 2020 23:54:12 +0000 (23:54 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1872363 13f79535-47bb-0310-9956-ffa450edef68

src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFChart.java

index 8b93f41eafaf9347ff4a5629f5fc002e18e1c74a..0b662e42f21bd063b8c5d06eebad53ac90657417 100644 (file)
@@ -188,6 +188,21 @@ public abstract class XDDFChart extends POIXMLDocumentPart implements TextContai
         return chart.getPlotArea();
     }
 
+    /**
+     * Clear all properties, as if a new instance had just been created.
+     * @since POI 4.1.2
+     */
+    public void clear() {
+        axes.clear();
+        seriesCount = 0;
+        if (workbook != null) {
+            workbook.removeSheetAt(0);
+            workbook.createSheet();
+        }
+        chart.set(CTChart.Factory.newInstance());
+        chart.addNewPlotArea();
+    }
+
     /**
      * @return true if only visible cells will be present on the chart, false
      *         otherwise
@@ -477,6 +492,78 @@ public abstract class XDDFChart extends POIXMLDocumentPart implements TextContai
         return series;
     }
 
+    /**
+     * Clear all chart series, as if a new instance had just been created.
+     * @since POI 4.1.2
+     */
+    public void clearChartSeries() {
+        CTPlotArea plotArea = getCTPlotArea();
+
+        for (int i = plotArea.sizeOfAreaChartArray(); i > 0; i--) {
+            plotArea.removeAreaChart(i - 1);
+        }
+
+        for (int i = plotArea.sizeOfArea3DChartArray(); i > 0; i--) {
+            plotArea.removeArea3DChart(i - 1);
+        }
+
+        for (int i = plotArea.sizeOfBarChartArray(); i > 0; i--) {
+            plotArea.removeBarChart(i - 1);
+        }
+
+        for (int i = plotArea.sizeOfBar3DChartArray(); i > 0; i--) {
+            plotArea.removeBar3DChart(i - 1);
+        }
+
+        for (int i = plotArea.sizeOfBubbleChartArray(); i > 0; i--) {
+            plotArea.removeBubbleChart(i - 1);
+        }
+
+        for (int i = plotArea.sizeOfDoughnutChartArray(); i > 0; i--) {
+            plotArea.removeDoughnutChart(i - 1);
+        }
+
+        for (int i = plotArea.sizeOfLineChartArray(); i > 0; i--) {
+            plotArea.removeLineChart(i - 1);
+        }
+
+        for (int i = plotArea.sizeOfLine3DChartArray(); i > 0; i--) {
+            plotArea.removeLine3DChart(i - 1);
+        }
+
+        for (int i = plotArea.sizeOfOfPieChartArray(); i > 0; i--) {
+            plotArea.removeOfPieChart(i - 1);
+        }
+
+        for (int i = plotArea.sizeOfPieChartArray(); i > 0; i--) {
+            plotArea.removePieChart(i - 1);
+        }
+
+        for (int i = plotArea.sizeOfPie3DChartArray(); i > 0; i--) {
+            plotArea.removePie3DChart(i - 1);
+        }
+
+        for (int i = plotArea.sizeOfRadarChartArray(); i > 0; i--) {
+            plotArea.removeRadarChart(i - 1);
+        }
+
+        for (int i = plotArea.sizeOfScatterChartArray(); i > 0; i--) {
+            plotArea.removeScatterChart(i - 1);
+        }
+
+        for (int i = plotArea.sizeOfStockChartArray(); i > 0; i--) {
+            plotArea.removeStockChart(i - 1);
+        }
+
+        for (int i = plotArea.sizeOfSurfaceChartArray(); i > 0; i--) {
+            plotArea.removeSurfaceChart(i - 1);
+        }
+
+        for (int i = plotArea.sizeOfSurface3DChartArray(); i > 0; i--) {
+            plotArea.removeSurface3DChart(i - 1);
+        }
+    }
+
     private Map<Long, XDDFChartAxis> getCategoryAxes() {
         CTPlotArea plotArea = getCTPlotArea();
         int sizeOfArray = plotArea.sizeOfCatAxArray();