poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From abea...@apache.org
Subject svn commit: r1841988 - in /poi/trunk/src: examples/src/org/apache/poi/xslf/usermodel/ examples/src/org/apache/poi/xssf/usermodel/examples/ examples/src/org/apache/poi/xwpf/usermodel/examples/ ooxml/java/org/apache/poi/xddf/usermodel/chart/
Date Wed, 26 Sep 2018 00:30:34 GMT
Author: abearez
Date: Wed Sep 26 00:30:33 2018
New Revision: 1841988

URL: http://svn.apache.org/viewvc?rev=1841988&view=rev
Log:
adapting some contributions by Axel Richter on SO

Added:
    poi/trunk/src/examples/src/org/apache/poi/xwpf/usermodel/examples/BarChartExample.java
      - copied, changed from r1841394, poi/trunk/src/examples/src/org/apache/poi/xwpf/usermodel/examples/BarChartExampleDOCX.java
Removed:
    poi/trunk/src/examples/src/org/apache/poi/xwpf/usermodel/examples/BarChartExampleDOCX.java
Modified:
    poi/trunk/src/examples/src/org/apache/poi/xslf/usermodel/BarChartDemo.java
    poi/trunk/src/examples/src/org/apache/poi/xssf/usermodel/examples/BarChart.java
    poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFBarChartData.java
    poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFChart.java
    poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFLineChartData.java
    poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFRadarChartData.java
    poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFScatterChartData.java

Modified: poi/trunk/src/examples/src/org/apache/poi/xslf/usermodel/BarChartDemo.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/examples/src/org/apache/poi/xslf/usermodel/BarChartDemo.java?rev=1841988&r1=1841987&r2=1841988&view=diff
==============================================================================
--- poi/trunk/src/examples/src/org/apache/poi/xslf/usermodel/BarChartDemo.java (original)
+++ poi/trunk/src/examples/src/org/apache/poi/xslf/usermodel/BarChartDemo.java Wed Sep 26
00:30:33 2018
@@ -115,6 +115,9 @@ public class BarChartDemo {
         // in order to transform a bar chart into a column chart, you just need to change
the bar direction
         bar.setBarDirection(BarDirection.COL);
 
+        // looking for "Stacked Bar Chart"? uncomment the following line
+        // bar.setBarGrouping(BarGrouping.STACKED);
+
         // additionally, you can adjust the axes
         bar.getCategoryAxis().setOrientation(AxisOrientation.MAX_MIN);
         bar.getValueAxes().get(0).setPosition(AxisPosition.TOP);

Modified: poi/trunk/src/examples/src/org/apache/poi/xssf/usermodel/examples/BarChart.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/examples/src/org/apache/poi/xssf/usermodel/examples/BarChart.java?rev=1841988&r1=1841987&r2=1841988&view=diff
==============================================================================
--- poi/trunk/src/examples/src/org/apache/poi/xssf/usermodel/examples/BarChart.java (original)
+++ poi/trunk/src/examples/src/org/apache/poi/xssf/usermodel/examples/BarChart.java Wed Sep
26 00:30:33 2018
@@ -28,8 +28,10 @@ import org.apache.poi.xddf.usermodel.XDD
 import org.apache.poi.xddf.usermodel.XDDFSolidFillProperties;
 import org.apache.poi.xddf.usermodel.chart.AxisCrosses;
 import org.apache.poi.xddf.usermodel.chart.AxisPosition;
+import org.apache.poi.xddf.usermodel.chart.BarDirection;
 import org.apache.poi.xddf.usermodel.chart.ChartTypes;
 import org.apache.poi.xddf.usermodel.chart.LegendPosition;
+import org.apache.poi.xddf.usermodel.chart.XDDFBarChartData;
 import org.apache.poi.xddf.usermodel.chart.XDDFCategoryAxis;
 import org.apache.poi.xddf.usermodel.chart.XDDFChartData;
 import org.apache.poi.xddf.usermodel.chart.XDDFChartLegend;
@@ -86,14 +88,14 @@ public class BarChart {
             data.addSeries(xs, ys2);
             chart.plot(data);
 
-            XDDFSolidFillProperties fill = new XDDFSolidFillProperties(XDDFColor.from(PresetColor.CHARTREUSE));
-            XDDFChartData.Series firstSeries = data.getSeries().get(0);
-            XDDFShapeProperties properties = firstSeries.getShapeProperties();
-            if (properties == null) {
-                properties = new XDDFShapeProperties();
-            }
-            properties.setFillProperties(fill);
-            firstSeries.setShapeProperties(properties);
+            // in order to transform a bar chart into a column chart, you just need to change
the bar direction
+            XDDFBarChartData bar = (XDDFBarChartData) data;
+            bar.setBarDirection(BarDirection.COL);
+            // looking for "Stacked Bar Chart"? uncomment the following line
+            // bar.setBarGrouping(BarGrouping.STACKED);
+
+            solidFillSeries(data, 0, PresetColor.CHARTREUSE);
+            solidFillSeries(data, 1, PresetColor.TURQUOISE);
 
             // Write the output to a file
             try (FileOutputStream fileOut = new FileOutputStream("ooxml-bar-chart.xlsx"))
{
@@ -101,4 +103,15 @@ public class BarChart {
             }
         }
     }
+
+    private static void solidFillSeries(XDDFChartData data, int index, PresetColor color)
{
+        XDDFSolidFillProperties fill = new XDDFSolidFillProperties(XDDFColor.from(color));
+        XDDFChartData.Series firstSeries = data.getSeries().get(index);
+        XDDFShapeProperties properties = firstSeries.getShapeProperties();
+        if (properties == null) {
+            properties = new XDDFShapeProperties();
+        }
+        properties.setFillProperties(fill);
+        firstSeries.setShapeProperties(properties);
+    }
 }

Copied: poi/trunk/src/examples/src/org/apache/poi/xwpf/usermodel/examples/BarChartExample.java
(from r1841394, poi/trunk/src/examples/src/org/apache/poi/xwpf/usermodel/examples/BarChartExampleDOCX.java)
URL: http://svn.apache.org/viewvc/poi/trunk/src/examples/src/org/apache/poi/xwpf/usermodel/examples/BarChartExample.java?p2=poi/trunk/src/examples/src/org/apache/poi/xwpf/usermodel/examples/BarChartExample.java&p1=poi/trunk/src/examples/src/org/apache/poi/xwpf/usermodel/examples/BarChartExampleDOCX.java&r1=1841394&r2=1841988&rev=1841988&view=diff
==============================================================================
--- poi/trunk/src/examples/src/org/apache/poi/xwpf/usermodel/examples/BarChartExampleDOCX.java
(original)
+++ poi/trunk/src/examples/src/org/apache/poi/xwpf/usermodel/examples/BarChartExample.java
Wed Sep 26 00:30:33 2018
@@ -43,9 +43,9 @@ import org.apache.poi.xwpf.usermodel.XWP
 /**
  * Build a bar chart from a template docx
  */
-public class BarChartExampleDOCX {
+public class BarChartExample {
     private static void usage(){
-        System.out.println("Usage: BarChartDemo <bar-chart-template.docx> <bar-chart-data.txt>");
+        System.out.println("Usage: BarChartExample <bar-chart-template.docx> <bar-chart-data.txt>");
         System.out.println("    bar-chart-template.docx     template with a bar chart");
         System.out.println("    bar-chart-data.txt          the model to set. First line
is chart title, " +
                 "then go pairs {axis-label value}");
@@ -119,6 +119,9 @@ public class BarChartExampleDOCX {
 
         // in order to transform a bar chart into a column chart, you just need to change
the bar direction
         bar.setBarDirection(BarDirection.COL);
+        
+        // looking for "Stacked Bar Chart"? uncomment the following line
+        // bar.setBarGrouping(BarGrouping.STACKED);
 
         // additionally, you can adjust the axes
         bar.getCategoryAxis().setOrientation(AxisOrientation.MAX_MIN);

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFBarChartData.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFBarChartData.java?rev=1841988&r1=1841987&r2=1841988&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFBarChartData.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFBarChartData.java Wed
Sep 26 00:30:33 2018
@@ -34,9 +34,24 @@ public class XDDFBarChartData extends XD
     public XDDFBarChartData(CTBarChart chart, Map<Long, XDDFChartAxis> categories,
             Map<Long, XDDFValueAxis> values) {
         this.chart = chart;
+        if (chart.getBarDir() == null) {
+            chart.addNewBarDir().setVal(BarDirection.BAR.underlying);
+        }
         for (CTBarSer series : chart.getSerList()) {
             this.series.add(new Series(series, series.getCat(), series.getVal()));
         }
+        defineAxes(categories, values);
+    }
+
+    private void defineAxes(Map<Long, XDDFChartAxis> categories, Map<Long, XDDFValueAxis>
values) {
+        if (chart.sizeOfAxIdArray() == 0) {
+            for (Long id : categories.keySet()) {
+                chart.addNewAxId().setVal(id);
+            }
+            for (Long id : values.keySet()) {
+                chart.addNewAxId().setVal(id);
+            }
+        }
         defineAxes(chart.getAxIdArray(), categories, values);
     }
 

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=1841988&r1=1841987&r2=1841988&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 Sep 26
00:30:33 2018
@@ -215,6 +215,34 @@ public abstract class XDDFChart extends
     }
 
     /**
+     * @since 4.0.1
+     */
+    public Boolean getTitleOverlay() {
+        if (chart.isSetTitle()) {
+            CTTitle title = chart.getTitle();
+            if (title.isSetOverlay()) {
+                return title.getOverlay().getVal();
+            }
+        }
+        return null;
+    }
+
+    /**
+     * @since 4.0.1
+     */
+    public void setTitleOverlay(boolean overlay) {
+        if (!chart.isSetTitle()) {
+            chart.addNewTitle();
+        }
+        CTTitle title = chart.getTitle();
+        if (title.isSetOverlay()) {
+            title.getOverlay().setVal(overlay);
+        } else {
+            title.addNewOverlay().setVal(overlay);
+        }
+    }
+
+    /**
      * Get the chart title body if there is one, i.e. title is set and is not a
      * formula.
      *
@@ -327,7 +355,7 @@ public abstract class XDDFChart extends
     private Map<Long, XDDFChartAxis> getCategoryAxes() {
         CTPlotArea plotArea = getCTPlotArea();
         int sizeOfArray = plotArea.sizeOfCatAxArray();
-        Map<Long, XDDFChartAxis> axes = new HashMap<Long, XDDFChartAxis>(sizeOfArray);
+        Map<Long, XDDFChartAxis> axes = new HashMap<>(sizeOfArray);
         for (int i = 0; i < sizeOfArray; i++) {
             CTCatAx category = plotArea.getCatAxArray(i);
             axes.put(category.getAxId().getVal(), new XDDFCategoryAxis(category));

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFLineChartData.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFLineChartData.java?rev=1841988&r1=1841987&r2=1841988&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFLineChartData.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFLineChartData.java Wed
Sep 26 00:30:33 2018
@@ -38,6 +38,18 @@ public class XDDFLineChartData extends X
         for (CTLineSer series : chart.getSerList()) {
             this.series.add(new Series(series, series.getCat(), series.getVal()));
         }
+        defineAxes(categories, values);
+    }
+
+    private void defineAxes(Map<Long, XDDFChartAxis> categories, Map<Long, XDDFValueAxis>
values) {
+        if (chart.sizeOfAxIdArray() == 0) {
+            for (Long id : categories.keySet()) {
+                chart.addNewAxId().setVal(id);
+            }
+            for (Long id : values.keySet()) {
+                chart.addNewAxId().setVal(id);
+            }
+        }
         defineAxes(chart.getAxIdArray(), categories, values);
     }
 

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFRadarChartData.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFRadarChartData.java?rev=1841988&r1=1841987&r2=1841988&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFRadarChartData.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFRadarChartData.java Wed
Sep 26 00:30:33 2018
@@ -38,6 +38,18 @@ public class XDDFRadarChartData extends
         for (CTRadarSer series : chart.getSerList()) {
             this.series.add(new Series(series, series.getCat(), series.getVal()));
         }
+        defineAxes(categories, values);
+    }
+
+    private void defineAxes(Map<Long, XDDFChartAxis> categories, Map<Long, XDDFValueAxis>
values) {
+        if (chart.sizeOfAxIdArray() == 0) {
+            for (Long id : categories.keySet()) {
+                chart.addNewAxId().setVal(id);
+            }
+            for (Long id : values.keySet()) {
+                chart.addNewAxId().setVal(id);
+            }
+        }
         defineAxes(chart.getAxIdArray(), categories, values);
     }
 

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFScatterChartData.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFScatterChartData.java?rev=1841988&r1=1841987&r2=1841988&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFScatterChartData.java
(original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFScatterChartData.java
Wed Sep 26 00:30:33 2018
@@ -38,6 +38,18 @@ public class XDDFScatterChartData extend
         for (CTScatterSer series : chart.getSerList()) {
             this.series.add(new Series(series, series.getXVal(), series.getYVal()));
         }
+        defineAxes(categories, values);
+    }
+
+    private void defineAxes(Map<Long, XDDFChartAxis> categories, Map<Long, XDDFValueAxis>
values) {
+        if (chart.sizeOfAxIdArray() == 0) {
+            for (Long id : categories.keySet()) {
+                chart.addNewAxId().setVal(id);
+            }
+            for (Long id : values.keySet()) {
+                chart.addNewAxId().setVal(id);
+            }
+        }
         defineAxes(chart.getAxIdArray(), categories, values);
     }
 
@@ -99,6 +111,28 @@ public class XDDFScatterChartData extend
             return series.getTx();
         }
 
+        /**
+         * @since 4.0.1
+         */
+        public Boolean getSmooth() {
+            if (series.isSetSmooth()) {
+                return series.getSmooth().getVal();
+            } else {
+                return null;
+            }
+        }
+
+        /**
+         * @since 4.0.1
+         */
+        public void setSmooth(boolean smooth) {
+            if (series.isSetSmooth()) {
+                series.getSmooth().setVal(smooth);
+            } else {
+                series.addNewSmooth().setVal(smooth);
+            }
+        }
+
         @Override
         public void setShowLeaderLines(boolean showLeaderLines) {
             if (!series.isSetDLbls()) {



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message