Spire.Presentation is a professional PowerPoint® compatible library that enables developers to create, read, write, modify, convert and Print PowerPoint documents. Get free and professional technical support for Spire.Presentation for .NET, Java, Android, C++, Python.

Tue Aug 20, 2024 1:42 pm

Problem:
When updating an existing chart's data, there might be a lot of unwanted data which is stored outside of the chart range. We need an efficient way of clearing/removing all this unwanted data which is not rendered in the chart.

At the moment, we are deleting the first 500 rows and columns. This is very slow. Is there a better way?

Example pptx:
clearchart.zip


Screenshot of the data not being
Clear-chart.png

boosted_d16
 
Posts: 34
Joined: Wed Apr 19, 2023 11:41 am

Wed Aug 21, 2024 7:10 am

Hello,

Thank you for your inquiry. I used the following code to clear the redundant chart data in your PPT document, which took about 6-7 seconds. What method are you using? If your side takes longer, you can try this way and let us know your testing result, look forward to your further feedback.
Code: Select all
 Presentation ppt= new Presentation();
            ppt.LoadFromFile("clearchart.pptx");
           if (ppt.Slides[0].Shapes[0] is IChart)
            {
                IChart chart = ppt.Slides[0].Shapes[0] as IChart;
                ChartData chartData = chart.ChartData;
                chartData.Clear(0, 4, 500, 500);
                chartData.Clear(5, 0, 500, 500);
            }
            ppt.SaveToFile("testClearchart.pptx", FileFormat.Pptx2019);

Sincerely,
Amin
E-iceblue support team
User avatar

Amin.Gan
 
Posts: 283
Joined: Mon Jul 15, 2024 5:40 am

Wed Aug 21, 2024 4:21 pm

This is the method we are using and like you said, it take 5-7 seconds per chart. We have 50+ charts in each pptx so it takes 4mins - 6 mins per pptx. Is there a better way?

boosted_d16
 
Posts: 34
Joined: Wed Apr 19, 2023 11:41 am

Thu Aug 22, 2024 9:48 am

Hello,

Thank you for your inquiry.
Sorry there is currently no faster way than using the 'Clear' interface. During the processing, it needs to traverse all the cells in the range for operation. Thanks for your understanding.

Sincerely,
Amin
E-iceblue support team
User avatar

Amin.Gan
 
Posts: 283
Joined: Mon Jul 15, 2024 5:40 am

Fri Aug 23, 2024 11:45 am

Is there a way to find out the furthest cell with a value vertically and horizontally in the range? so we can dynamically pass in the row and col instead of blindly saying 500 x 500. This should save us some time. Reducing the size of the clear functionality might be quicker.

Code: Select all
chartData.Clear(5, 0, x, y);

boosted_d16
 
Posts: 34
Joined: Wed Apr 19, 2023 11:41 am

Mon Aug 26, 2024 9:25 am

Hello,

Thank you for your inquiry. At present, there is no way to find out the furthest cell with a value vertically and horizontally in the range. We will consider adding a new feature to support it. If it is available in the future, we will let you know.Thanks for your understanding.

Sincerely,
Amin
E-iceblue support team
User avatar

Amin.Gan
 
Posts: 283
Joined: Mon Jul 15, 2024 5:40 am

Mon Sep 23, 2024 1:34 am

Hello,

Now, our product supports obtaining the last row and last column of the data source for charts, welcome to download it from the following link and test it.

Our website link: https://www.e-iceblue.com/Download/download-presentation-for-net-now.html
NuGet link: https://www.nuget.org/packages/Spire.Presentation/9.9.2

You can refer to the following code.If you have any other questions, please feel free to write to me.
Code: Select all
   int lastRow = chart.ChartData.LastRowIndex;
   int lastCol = chart.ChartData.LastColIndex;
   int dataRow = chart.Series[2].Values[chart.Series[2].Values.Count - 1].Row;
   int dataColumn = chart.Series[2].Values[chart.Series[2].Values.Count - 1].Column;
   chart.ChartData.Clear(dataRow + 1, 0, lastRow + 1, lastCol + 1); 
   chart.ChartData.Clear(0, dataColumn + 1, lastRow + 1, lastCol + 1);

Sincerely,
Amin
E-iceblue support team
User avatar

Amin.Gan
 
Posts: 283
Joined: Mon Jul 15, 2024 5:40 am

Return to Spire.Presentation

cron