https://bz.apache.org/bugzilla/show_bug.cgi?id=63153 Bug ID: 63153
Summary: Removing a data series from a scatter chart corrupts
the workbook
Product: POI
Version: 4.0.x-dev
Hardware: PC
Status: NEW
Severity: normal
Priority: P2
Component: XDDF
Assignee:
[hidden email]
Reporter:
[hidden email]
Target Milestone: ---
If a series is removed from a scatter chart, the workbook is corrupted. When
Excel 2011 for Mac or Excel 2010 opens the workbook, Excel reports that the
workbook is damaged. I am using POI version 4.0.1
This has been seen both in charts added to a workbook, and charts that are
already in existing workbooks.
The code below adds a sheet to a workbook, adds a scatter chart to the sheet,
and adds two data series to the chart. If nMaxSeries is set to 2 or more, the
series are not removed from the chart, and the workbook is not corrupted. If
nMaxSeries is set to less than 2, at least one series is removed from the chart
and the workbook is corrupted.
/**
* This method creates a scatter chart in workbook, and adds two data
* series. If either scatter series is removed, the chart is damaged.
*
* @param dstWorkbook
*/
private static void removeChartSeriesTest(XSSFWorkbook dstWorkbook) {
final String procName = "removeChartSeriesTest";
final int nMaxSeries = 1;
final XSSFSheet sheet = dstWorkbook.createSheet("Remove series
test");
final XSSFDrawing xssfDrawing = sheet.createDrawingPatriarch();
final XSSFClientAnchor anchor = xssfDrawing.createAnchor(0, 0,
0, 0, 1, 5, 20, 20);
final XDDFChart chart = xssfDrawing.createChart(anchor);
final XDDFValueAxis bottomAxis =
chart.createValueAxis(AxisPosition.BOTTOM);
final XDDFValueAxis leftAxis =
chart.createValueAxis(AxisPosition.LEFT);
// Initialize data data sources
final Double dX[] = new Double[5];
final Double dY1[] = new Double[5];
final Double dY2[] = new Double[5];
for (int n = 0; n < 5; ++n) {
dX[n] = (double) n;
dY1[n] = 2.0 * n;
dY2[n] = (double) (n * n);
}
final XDDFNumericalDataSource<Double> xData =
XDDFDataSourcesFactory.fromArray(dX, null);
final XDDFNumericalDataSource<Double> yData1 =
XDDFDataSourcesFactory.fromArray(dY1, null);
final XDDFNumericalDataSource<Double> yData2 =
XDDFDataSourcesFactory.fromArray(dY2, null);
// Creat the chartdata
final XDDFScatterChartData chartData = (XDDFScatterChartData)
chart.createData(ChartTypes.SCATTER, bottomAxis,
leftAxis);
// Add the series
chartData.addSeries(xData, yData1);
chartData.addSeries(xData, yData2);
System.out.println(String.format("\r\n%s:
chartData.getSeries.size=%d nMaxSheets=%d", procName,
chartData.getSeries().size(), nMaxSeries));
// Remove any extra series
while (chartData.getSeries().size() > nMaxSeries) {
chartData.getSeries().remove(0);
}
System.out.println(String.format("%s:
chartData.getSeries.size=%d", procName, chartData.getSeries().size()));
// Finish up
chart.plot(chartData);
final int nSheet = dstWorkbook.getSheetIndex(sheet);
dstWorkbook.setSelectedTab(nSheet);
dstWorkbook.setActiveSheet(nSheet);
dstWorkbook.setFirstVisibleTab(nSheet);
}
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail:
[hidden email]
For additional commands, e-mail:
[hidden email]