poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From abea...@apache.org
Subject svn commit: r1842687 - in /poi/trunk/src: examples/src/org/apache/poi/xslf/usermodel/ examples/src/org/apache/poi/xwpf/usermodel/examples/ ooxml/java/org/apache/poi/xddf/usermodel/chart/ ooxml/testcases/org/apache/poi/xslf/usermodel/
Date Wed, 03 Oct 2018 08:20:50 GMT
Author: abearez
Date: Wed Oct  3 08:20:50 2018
New Revision: 1842687

URL: http://svn.apache.org/viewvc?rev=1842687&view=rev
Log:
change chart data to experiment diverse scripts

Modified:
    poi/trunk/src/examples/src/org/apache/poi/xslf/usermodel/BarChartDemo.java
    poi/trunk/src/examples/src/org/apache/poi/xslf/usermodel/PieChartDemo.java
    poi/trunk/src/examples/src/org/apache/poi/xslf/usermodel/bar-chart-data.txt
    poi/trunk/src/examples/src/org/apache/poi/xwpf/usermodel/examples/BarChartExample.java
    poi/trunk/src/examples/src/org/apache/poi/xwpf/usermodel/examples/bar-chart-data.txt
    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/XDDFChartData.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFChart.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=1842687&r1=1842686&r2=1842687&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 Oct  3
08:20:50 2018
@@ -59,26 +59,30 @@ public class BarChartDemo {
             BufferedReader modelReader = new BufferedReader(new FileReader(args[1]))) {
 
             String chartTitle = modelReader.readLine();  // first line is chart title
+            String[] series = modelReader.readLine().split(",");
 
             // Category Axis Data
-            List<String> listCategories = new ArrayList<String>(3);
+            List<String> listLanguages = new ArrayList<>(10);
 
             // Values
-            List<Double> listValues = new ArrayList<Double>(3);
+            List<Double> listCountries = new ArrayList<>(10);
+            List<Double> listSpeakers = new ArrayList<>(10);
 
             // set model
             String ln;
-            while((ln = modelReader.readLine()) != null){
-                String[] vals = ln.split("\\s+");
-                listCategories.add(vals[0]);
-                listValues.add(Double.valueOf(vals[1]));
+            while((ln = modelReader.readLine()) != null) {
+                String[] vals = ln.split(",");
+                listCountries.add(Double.valueOf(vals[0]));
+                listSpeakers.add(Double.valueOf(vals[1]));
+                listLanguages.add(vals[2]);
             }
-            String[] categories = listCategories.toArray(new String[listCategories.size()]);
-            Double[] values = listValues.toArray(new Double[listValues.size()]);
+            String[] categories = listLanguages.toArray(new String[listLanguages.size()]);
+            Double[] values1 = listCountries.toArray(new Double[listCountries.size()]);
+            Double[] values2 = listSpeakers.toArray(new Double[listSpeakers.size()]);
 
             try (XMLSlideShow pptx = new XMLSlideShow(argIS)) {
                 XSLFSlide slide = pptx.getSlides().get(0);
-                setBarData(findChart(slide), chartTitle, categories, values);
+                setBarData(findChart(slide), chartTitle, series, categories, values1, values2);
 
                 XSLFChart chart = findChart(pptx.createSlide().importContent(slide));
                 setColumnData(chart, "Column variant");
@@ -91,18 +95,22 @@ public class BarChartDemo {
         }
     }
 
-    private static void setBarData(XSLFChart chart, String chartTitle, String[] categories,
Double[] values) {
-        final List<XDDFChartData> series = chart.getChartSeries();
-        final XDDFBarChartData bar = (XDDFBarChartData) series.get(0);
+    private static void setBarData(XSLFChart chart, String chartTitle, String[] series, String[]
categories, Double[] values1, Double[] values2) {
+        final List<XDDFChartData> data = chart.getChartSeries();
+        final XDDFBarChartData bar = (XDDFBarChartData) data.get(0);
 
         final int numOfPoints = categories.length;
         final String categoryDataRange = chart.formatRange(new CellRangeAddress(1, numOfPoints,
0, 0));
         final String valuesDataRange = chart.formatRange(new CellRangeAddress(1, numOfPoints,
1, 1));
-        final XDDFDataSource<?> categoriesData = XDDFDataSourcesFactory.fromArray(categories,
categoryDataRange);
-        final XDDFNumericalDataSource<? extends Number> valuesData = XDDFDataSourcesFactory.fromArray(values,
valuesDataRange);
-
+        final String valuesDataRange2 = chart.formatRange(new CellRangeAddress(1, numOfPoints,
2, 2));
+        final XDDFDataSource<?> categoriesData = XDDFDataSourcesFactory.fromArray(categories,
categoryDataRange, 0);
+        final XDDFNumericalDataSource<? extends Number> valuesData = XDDFDataSourcesFactory.fromArray(values1,
valuesDataRange, 1);
+        values1[6] = 16.0; // if you ever want to change the underlying data
+        final XDDFNumericalDataSource<? extends Number> valuesData2 = XDDFDataSourcesFactory.fromArray(values2,
valuesDataRange2, 2);
         bar.getSeries().get(0).replaceData(categoriesData, valuesData);
-        bar.getSeries().get(0).setTitle(chartTitle, chart.setSheetTitle(chartTitle));
+        bar.addSeries(categoriesData, valuesData2);
+        bar.getSeries().get(0).setTitle(series[0], chart.setSheetTitle(series[0], 0));
+        bar.getSeries().get(1).setTitle(series[1], chart.setSheetTitle(series[1], 1));
         chart.plot(bar);
     }
 
@@ -110,7 +118,6 @@ public class BarChartDemo {
         // Series Text
         List<XDDFChartData> series = chart.getChartSeries();
         XDDFBarChartData bar = (XDDFBarChartData) series.get(0);
-        bar.getSeries().get(0).setTitle(chartTitle, chart.setSheetTitle(chartTitle));
 
         // in order to transform a bar chart into a column chart, you just need to change
the bar direction
         bar.setBarDirection(BarDirection.COL);

Modified: poi/trunk/src/examples/src/org/apache/poi/xslf/usermodel/PieChartDemo.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/examples/src/org/apache/poi/xslf/usermodel/PieChartDemo.java?rev=1842687&r1=1842686&r2=1842687&view=diff
==============================================================================
--- poi/trunk/src/examples/src/org/apache/poi/xslf/usermodel/PieChartDemo.java (original)
+++ poi/trunk/src/examples/src/org/apache/poi/xslf/usermodel/PieChartDemo.java Wed Oct  3
08:20:50 2018
@@ -77,10 +77,10 @@ public class PieChartDemo {
 	            XDDFPieChartData pie = (XDDFPieChartData) series.get(0);
 
 	            // Category Axis Data
-	            List<String> listCategories = new ArrayList<String>(3);
+	            List<String> listCategories = new ArrayList<>(3);
 
 	            // Values
-	            List<Double> listValues = new ArrayList<Double>(3);
+	            List<Double> listValues = new ArrayList<>(3);
 
 	            // set model
 	            String ln;
@@ -100,7 +100,7 @@ public class PieChartDemo {
 
 	            XDDFPieChartData.Series firstSeries = (XDDFPieChartData.Series) pie.getSeries().get(0);
 	            firstSeries.replaceData(categoriesData, valuesData);
-	            firstSeries.setTitle(chartTitle, chart.setSheetTitle(chartTitle));
+	            firstSeries.setTitle(chartTitle, chart.setSheetTitle(chartTitle, 0));
 	            firstSeries.setExplosion(25);
 	            chart.plot(pie);
 

Modified: poi/trunk/src/examples/src/org/apache/poi/xslf/usermodel/bar-chart-data.txt
URL: http://svn.apache.org/viewvc/poi/trunk/src/examples/src/org/apache/poi/xslf/usermodel/bar-chart-data.txt?rev=1842687&r1=1842686&r2=1842687&view=diff
==============================================================================
--- poi/trunk/src/examples/src/org/apache/poi/xslf/usermodel/bar-chart-data.txt (original)
+++ poi/trunk/src/examples/src/org/apache/poi/xslf/usermodel/bar-chart-data.txt Wed Oct  3
08:20:50 2018
@@ -1,4 +1,12 @@
-My Bar or Column Chart
-First 1.0
-Second 3.0
-Third 4.0
\ No newline at end of file
+10 languages with most speakers as first language
+countries,speakers,language
+58,315,العربية
+4,243,বাংলা
+38,1299,中文
+118,378,English
+4,260,हिन्दी
+2,128,日本語
+15,223,português
+6,119,ਪੰਜਾਬੀ
+18,154,Русский язык
+31,442,español

Modified: poi/trunk/src/examples/src/org/apache/poi/xwpf/usermodel/examples/BarChartExample.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/examples/src/org/apache/poi/xwpf/usermodel/examples/BarChartExample.java?rev=1842687&r1=1842686&r2=1842687&view=diff
==============================================================================
--- poi/trunk/src/examples/src/org/apache/poi/xwpf/usermodel/examples/BarChartExample.java
(original)
+++ poi/trunk/src/examples/src/org/apache/poi/xwpf/usermodel/examples/BarChartExample.java
Wed Oct  3 08:20:50 2018
@@ -61,26 +61,30 @@ public class BarChartExample {
                 BufferedReader modelReader = new BufferedReader(new FileReader(args[1])))
{
 
             String chartTitle = modelReader.readLine();  // first line is chart title
+            String[] series = modelReader.readLine().split(",");
 
             // Category Axis Data
-            List<String> listCategories = new ArrayList<String>(3);
+            List<String> listLanguages = new ArrayList<>(10);
 
             // Values
-            List<Double> listValues = new ArrayList<Double>(3);
+            List<Double> listCountries = new ArrayList<>(10);
+            List<Double> listSpeakers = new ArrayList<>(10);
 
             // set model
             String ln;
             while((ln = modelReader.readLine()) != null) {
-                String[] vals = ln.split("\\s+");
-                listCategories.add(vals[0]);
-                listValues.add(Double.valueOf(vals[1]));
+                String[] vals = ln.split(",");
+                listCountries.add(Double.valueOf(vals[0]));
+                listSpeakers.add(Double.valueOf(vals[1]));
+                listLanguages.add(vals[2]);
             }
-            String[] categories = listCategories.toArray(new String[listCategories.size()]);
-            Double[] values = listValues.toArray(new Double[listValues.size()]);
+            String[] categories = listLanguages.toArray(new String[listLanguages.size()]);
+            Double[] values1 = listCountries.toArray(new Double[listCountries.size()]);
+            Double[] values2 = listSpeakers.toArray(new Double[listSpeakers.size()]);
 
             try (XWPFDocument doc = new XWPFDocument(argIS)) {
                 XWPFChart chart = doc.getCharts().get(0);
-                setBarData(chart, chartTitle, categories, values);
+                setBarData(chart, chartTitle, series, categories, values1, values2);
                 chart = doc.getCharts().get(1);
                 setColumnData(chart, "Column variant");
 
@@ -93,21 +97,22 @@ public class BarChartExample {
         System.out.println("Done");
     }
 
-    private static void setBarData(XWPFChart chart, String chartTitle, String[] categories,
Double[] values) {
-        final List<XDDFChartData> series = chart.getChartSeries();
-        final XDDFBarChartData bar = (XDDFBarChartData) series.get(0);
+    private static void setBarData(XWPFChart chart, String chartTitle, String[] series, String[]
categories, Double[] values1, Double[] values2) {
+        final List<XDDFChartData> data = chart.getChartSeries();
+        final XDDFBarChartData bar = (XDDFBarChartData) data.get(0);
 
         final int numOfPoints = categories.length;
         final String categoryDataRange = chart.formatRange(new CellRangeAddress(1, numOfPoints,
0, 0));
         final String valuesDataRange = chart.formatRange(new CellRangeAddress(1, numOfPoints,
1, 1));
         final String valuesDataRange2 = chart.formatRange(new CellRangeAddress(1, numOfPoints,
2, 2));
         final XDDFDataSource<?> categoriesData = XDDFDataSourcesFactory.fromArray(categories,
categoryDataRange, 0);
-        final XDDFNumericalDataSource<? extends Number> valuesData = XDDFDataSourcesFactory.fromArray(values,
valuesDataRange, 1);
-        values[2] = 10.0;
-        final XDDFNumericalDataSource<? extends Number> valuesData2 = XDDFDataSourcesFactory.fromArray(values,
valuesDataRange2, 2);
+        final XDDFNumericalDataSource<? extends Number> valuesData = XDDFDataSourcesFactory.fromArray(values1,
valuesDataRange, 1);
+        values1[6] = 16.0; // if you ever want to change the underlying data
+        final XDDFNumericalDataSource<? extends Number> valuesData2 = XDDFDataSourcesFactory.fromArray(values2,
valuesDataRange2, 2);
         bar.getSeries().get(0).replaceData(categoriesData, valuesData);
         bar.addSeries(categoriesData, valuesData2);
-        bar.getSeries().get(0).setTitle(chartTitle, chart.setSheetTitle(chartTitle));
+        bar.getSeries().get(0).setTitle(series[0], chart.setSheetTitle(series[0], 0));
+        bar.getSeries().get(1).setTitle(series[1], chart.setSheetTitle(series[1], 1));
         chart.plot(bar);
     }
 
@@ -115,11 +120,10 @@ public class BarChartExample {
         // Series Text
         List<XDDFChartData> series = chart.getChartSeries();
         XDDFBarChartData bar = (XDDFBarChartData) series.get(0);
-        bar.getSeries().get(0).setTitle(chartTitle, chart.setSheetTitle(chartTitle));
 
         // 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);
 

Modified: poi/trunk/src/examples/src/org/apache/poi/xwpf/usermodel/examples/bar-chart-data.txt
URL: http://svn.apache.org/viewvc/poi/trunk/src/examples/src/org/apache/poi/xwpf/usermodel/examples/bar-chart-data.txt?rev=1842687&r1=1842686&r2=1842687&view=diff
==============================================================================
--- poi/trunk/src/examples/src/org/apache/poi/xwpf/usermodel/examples/bar-chart-data.txt (original)
+++ poi/trunk/src/examples/src/org/apache/poi/xwpf/usermodel/examples/bar-chart-data.txt Wed
Oct  3 08:20:50 2018
@@ -1,4 +1,12 @@
-My Bar or Column Chart
-First 1.0
-Second 3.0
-Third 4.0
\ No newline at end of file
+10 languages with most speakers as first language
+countries,speakers,language
+58,315,العربية
+4,243,বাংলা
+38,1299,中文
+118,378,English
+4,260,हिन्दी
+2,128,日本語
+15,223,português
+6,119,ਪੰਜਾਬੀ
+18,154,Русский язык
+31,442,español

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=1842687&r1=1842686&r2=1842687&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
Oct  3 08:20:50 2018
@@ -109,6 +109,7 @@ public class XDDFBarChartData extends XD
             XDDFNumericalDataSource<? extends Number> values) {
         final int index = this.series.size();
         final CTBarSer ctSer = this.chart.addNewSer();
+        ctSer.addNewTx();
         ctSer.addNewCat();
         ctSer.addNewVal();
         ctSer.addNewIdx().setVal(index);

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=1842687&r1=1842686&r2=1842687&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 Oct  3
08:20:50 2018
@@ -669,20 +669,22 @@ public abstract class XDDFChart extends
     }
 
     /**
-     * set sheet time in excel file
+     * set sheet title in excel file
      *
      * @param title
      *            title of sheet
+     * @param column
+     *            column index
      * @return return cell reference
      * @since POI 4.0.0
      */
-    public CellReference setSheetTitle(String title) {
+    public CellReference setSheetTitle(String title, int column) {
         XSSFSheet sheet = getSheet();
         XSSFRow row = this.getRow(sheet, 0);
-        XSSFCell cell = this.getCell(row, 1);
+        XSSFCell cell = this.getCell(row, column);
         cell.setCellValue(title);
-        this.updateSheetTable(sheet.getTables().get(0).getCTTable(), title, 1);
-        return new CellReference(sheet.getSheetName(), 0, 1, true, true);
+        this.updateSheetTable(sheet.getTables().get(0).getCTTable(), title, column);
+        return new CellReference(sheet.getSheetName(), 0, column, true, true);
     }
 
     /**
@@ -698,12 +700,11 @@ public abstract class XDDFChart extends
     private void updateSheetTable(CTTable ctTable, String title, int index) {
         CTTableColumns tableColumnList = ctTable.getTableColumns();
         CTTableColumn column = null;
-        if (tableColumnList.getCount() >= index) {
-            column = tableColumnList.getTableColumnArray(index);
-        } else {
+        for( int i = 0; tableColumnList.getCount() < index; i++) {
             column = tableColumnList.addNewTableColumn();
-            column.setId(index);
+            column.setId(i);
         }
+        column = tableColumnList.getTableColumnArray(index);
         column.setName(title);
     }
 

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFChartData.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFChartData.java?rev=1842687&r1=1842686&r2=1842687&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFChartData.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFChartData.java Wed Oct
 3 08:20:50 2018
@@ -130,6 +130,10 @@ public abstract class XDDFChartData {
                 } else {
                     cache = ref.addNewStrCache();
                 }
+                if (cache.sizeOfPtArray() < 1) {
+                    cache.addNewPtCount().setVal(1);
+                    cache.addNewPt().setIdx(0);;
+                }
                 cache.getPtArray(0).setV(title);
                 ref.setF(titleRef.formatAsString());
             }

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFChart.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFChart.java?rev=1842687&r1=1842686&r2=1842687&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFChart.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFChart.java Wed Oct
 3 08:20:50 2018
@@ -158,7 +158,7 @@ public class TestXSLFChart {
         final XDDFNumericalDataSource<Integer> valuesData = XDDFDataSourcesFactory.fromArray(values,
valuesDataRange);
         series.replaceData(categoryData, valuesData);
         final String title = "Apache POI";
-        series.setTitle(title, chart.setSheetTitle(title));
+        series.setTitle(title, chart.setSheetTitle(title, 0));
         chart.plot(data);
 	}
 



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


Mime
View raw message