'How to get updated category or value range from pivot chart on deleting rows from pivot data source?

I am using the below code to get pivot chart categorydata range. The issue is when I delete some rows from pivot table data source and get the pivot table category or value range from chart I get the previous/same range i.e. before deleting the rows from pivot source. How can I get the updated range of pivot from chart category or value range?

SeriesCollection series = chart.getNSeries();

String categoryDataRange = series.getCategoryData();



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source