aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAlain Béarez <abearez@apache.org>2021-01-19 21:33:38 +0000
committerAlain Béarez <abearez@apache.org>2021-01-19 21:33:38 +0000
commit825bebdbd198210211df8c0aec9e687fbb56abed (patch)
treeedaf774602df6e0ae1a16088d7cb632d9b47c626 /src
parent5de42f466f6aed8c61c7743186d18ee128e18823 (diff)
downloadpoi-825bebdbd198210211df8c0aec9e687fbb56abed.tar.gz
poi-825bebdbd198210211df8c0aec9e687fbb56abed.zip
Bug 65016 - Creating a chart throws exception
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1885700 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src')
-rw-r--r--src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFDataSource.java4
-rw-r--r--src/ooxml/testcases/org/apache/poi/xddf/usermodel/chart/TestXDDFChart.java43
2 files changed, 45 insertions, 2 deletions
diff --git a/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFDataSource.java b/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFDataSource.java
index e6f085e807..439d0a325c 100644
--- a/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFDataSource.java
+++ b/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFDataSource.java
@@ -80,7 +80,9 @@ public interface XDDFDataSource<T> {
}
}
if (effectiveNumOfPoints == 0) {
- cache.unsetPtCount();
+ if (cache.isSetPtCount()) {
+ cache.unsetPtCount();
+ }
} else {
if (cache.isSetPtCount()) {
cache.getPtCount().setVal(numOfPoints);
diff --git a/src/ooxml/testcases/org/apache/poi/xddf/usermodel/chart/TestXDDFChart.java b/src/ooxml/testcases/org/apache/poi/xddf/usermodel/chart/TestXDDFChart.java
index 4ace282749..66196d375b 100644
--- a/src/ooxml/testcases/org/apache/poi/xddf/usermodel/chart/TestXDDFChart.java
+++ b/src/ooxml/testcases/org/apache/poi/xddf/usermodel/chart/TestXDDFChart.java
@@ -23,9 +23,17 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
import org.apache.poi.ooxml.POIXMLFactory;
import org.apache.poi.ooxml.POIXMLRelation;
+import org.apache.poi.ss.util.CellRangeAddress;
+import org.apache.poi.xssf.XSSFTestDataSamples;
+import org.apache.poi.xssf.usermodel.XSSFSheet;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.junit.jupiter.api.Test;
import org.openxmlformats.schemas.drawingml.x2006.chart.CTChartSpace;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+
class TestXDDFChart {
@Test
void testConstruct() {
@@ -48,6 +56,39 @@ class TestXDDFChart {
assertEquals("rid2", ctChartSpace.getExternalData().getId());
}
+ @Test
+ public void test65016() throws IOException {
+ try (XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("65016.xlsx")) {
+ XSSFSheet splitSheet = wb.getSheet("Splits");
+
+ XDDFChart chart = newXDDFChart();
+ XDDFChartLegend legend = chart.getOrAddLegend();
+ legend.setPosition(LegendPosition.BOTTOM);
+
+ // Use a category axis for the bottom axis.
+ XDDFCategoryAxis bottomAxis = chart.createCategoryAxis(AxisPosition.BOTTOM);
+ XDDFValueAxis leftAxis = chart.createValueAxis(AxisPosition.LEFT);
+ leftAxis.setCrosses(AxisCrosses.AUTO_ZERO);
+
+ XDDFLineChartData data = (XDDFLineChartData) chart.createData(ChartTypes.LINE, bottomAxis, leftAxis);
+
+ // starting row 1 to include description
+ XDDFNumericalDataSource<Double> xs = XDDFDataSourcesFactory.fromNumericCellRange(splitSheet,
+ new CellRangeAddress(2, 100, 0, 0));
+ XDDFNumericalDataSource<Double> ys1 = XDDFDataSourcesFactory.fromNumericCellRange(splitSheet,
+ new CellRangeAddress(2, 100, 1, 1));
+
+ XDDFLineChartData.Series series = (XDDFLineChartData.Series) data.addSeries(xs, ys1);
+ assertEquals(series.categoryData.getPointCount(), xs.getPointCount());
+
+ chart.plot(data);
+
+ try (OutputStream out = new FileOutputStream("/tmp/chart20201220.xlsx")) {
+ wb.write(out);
+ }
+ }
+ }
+
private XDDFChart newXDDFChart() {
XDDFChart xddfChart = new XDDFChart() {
@Override
@@ -67,4 +108,4 @@ class TestXDDFChart {
};
return xddfChart;
}
-} \ No newline at end of file
+}