Bug 52067 - HSSFChart createSeries not working properly when adding more than one series
Summary: HSSFChart createSeries not working properly when adding more than one series
Status: NEW
Alias: None
Product: POI
Classification: Unclassified
Component: HSSF (show other bugs)
Version: 3.7-FINAL
Hardware: PC Windows XP
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-10-21 09:32 UTC by Maria
Modified: 2013-02-26 14:32 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Maria 2011-10-21 09:32:55 UTC
I have a worksheet with 2 sheets. In the 1st sheet i have the data and in the 2nd one a graph - i open it thru java and load data into 1st sheet and then i need to create some series in 2nd tab's graph dynamically depending on data.

The graph already have a dummy series - I need it to have setSeriesTitle working and I will delete it later.

When I add a new series to the graph, it works fine. The problem is if I add more than one. My file gets corrupted and if I add 4 series to the graph it only displays 3...

This is my code:

HSSFSeries series;
int employeeGradedPercColumn=4;
CellRangeAddress productsRange = new CellRangeAddress(rowStartingSecondReport+1, rowStartingSecondReport+totalProducts, 1, 1) ;            
Iterator<String> iterator = employeeSeriesHeader.iterator();
while(iterator.hasNext()){            	
            	series = chart.createSeries();
                series.setCategoryLabelsCellRange(productsRange) ;
                series.setValuesCellRange( new CellRangeAddress( rowStartingSecondReport+1, rowStartingSecondReport+totalProducts, employeeGradedPercColumn, employeeGradedPercColumn)) ;
                series.setSeriesTitle(iterator.next()); 
                employeeGradedPercColumn=employeeGradedPercColumn+2;                 
            }

Thanks,
Maria
Comment 1 s.boutsis 2013-02-03 17:09:46 UTC
I'm seeing the exact same behavior using version 3.9.
I create lots of series in a loop, using a pre-constructed excel file (template). When I open up the modified file in Excel, the charts shows series 1,2,3, then series 11,12,13, then 18,19,20. All other series are missing.

Can someone please provide a solution or workaround?
Comment 2 Maciej 2013-02-26 14:32:35 UTC
I think I pinned down this bug. Reason is new series are cloned into sheet records one index too late.

Lines 1208~1209:
/* next index in the records list where the new series can be inserted */
idx = endSeriesRecordIdx + 1;

just change idx to:
idx = endSeriesRecordIdx;

Works for me. Unfortunately I am not able to provide test case covering this - bug shows only after opening file in Excel.