Chart data area does not expand automatically


I have found, that data row expanding does not work correctly. (12.2 KB)
I have 2 charts. First has data for it on the same sheet (Chart1). Second chart has data for it on different worksheet (Data2). When I insert columns into data row for the first chart I have correct behavior - data charts are expanding (as like Excel) (1st part of test). When I insert columns into data row for the second chart I have wrong behavior - data charts are not expanding (not like Excel) (2nd part of test).

public void chart_data_one_worksheet() throws Exception {
    Workbook workbook = new Workbook("E://in.xlsx");
    Worksheet dataSheet = workbook.getWorksheets().get("Chart1");
    Cells cells = dataSheet.getCells();
    Chart chart = dataSheet.getCharts().get(0);
    String chartValuesBefore = chart.getNSeries().get(0).getValues();
    String chartValuesAfter = chart.getNSeries().get(0).getValues();
    assertNotEquals(chartValuesBefore, chartValuesAfter);

    dataSheet = workbook.getWorksheets().get("Data2");
    cells = dataSheet.getCells();
    chart = workbook.getWorksheets().get("Chart2").getCharts().get(0);
    chartValuesBefore = chart.getNSeries().get(0).getValues();
    chartValuesAfter = chart.getNSeries().get(0).getValues();
    assertNotEquals(chartValuesBefore, chartValuesAfter);

Best regards. Alexey


Could you please share a sample application which includes saving of output file. Also share the output file and screenshots. I have updated one line of code in your method and getting the error with latest version of API.

java.lang.AssertionError: Values should be different. Actual: =Data2!$B$1:$C$1

where the updated code is:

org.junit.Assert.assertNotEquals(chartValuesBefore, chartValuesAfter);

So please share runnable application for our testing. We will reproduce the problem and provide our feedback after analysis. (6.5 MB)

Hi. Ofcourse this test is not successful because the library works in wrong way.

Please, insert following line before the last assertion line“E://out.xlsx”);

And you will see, that chart on worksheet Chart1 had changed the data range, whereas chart on worksheet Chart2 had not.

Data2.jpg (21.3 KB)
Chart1.jpg (59.6 KB)
Chart2.jpg (15.5 KB)


I have added a value manually at Column H of Data2 worksheet in the input file “in.xlsx” but MS Excel 2016 does not update the data range automatically. Excel.PNG (23.5 KB)

However, I have logged it in our database for investigations. Once, we will have some news for you, we will update you in this topic.

This has been logged as

CELLSJAVA-42880 - Chart data area does not expand automatically


Idea, that we set a data range for chart at start, then we insert columns between initial columns and range of chart is expanded too.
It works, when data range located on the same sheet. But it does not work for data range located on another worksheet

Best regards. Alexey


We have recorded your comments with the ticket and will share our feedback with you soon.


Please use the following line of code to fix your issue:
Sample code:


Please note, only when the parameter “updateReference” is true, the reference of other worksheets are updated.