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.

Mon Apr 03, 2023 2:03 am

Hello,
I am seeing error when I create a line chart with empty or null values. It seems like chart is broken when trying to switch rows and columns.

Here is sample powerpoint with null values:
sample with empty values.zip

In the powerpoint, chart in slide 1 with empty values gets broken when you try to switch rows and columns
Meanwhile, chart in slide 1 with NO empty values switch can rows and columns

Sample code snippet:
Code: Select all
// set chart data
if(data is Null or data is empty string)
{
 chart.ChartData[x,y].Value = "";
}
else
{
  chart.ChartData[x,y].NumberValue = data;
}

boncyrus
 
Posts: 20
Joined: Wed Mar 01, 2023 10:01 am

Mon Apr 03, 2023 7:46 am

Hi,

Thank you for your message.
I used the following code to test your document with the latest version (Spire. presentation 8.3.2), but I did not reproduce your problem. Are you using this version? If not, I recommend that you upgrade to the latest version to try again. If your problem still exists, please provide the following more information to us for further investigation.
1. Your complete test code
2. The target platform of your project(E.g. .NET framework 4.8 )
3. Your system information (E.g. Win10, 64 bit) and region setting (E.g. China, Chinese).

Code: Select all
            Presentation ppt = new Presentation();
            ppt.LoadFromFile(@"sample.pptx");
            if (ppt.Slides[0].Shapes[0] is IChart)
            {
                IChart chart = ppt.Slides[0].Shapes[0] as IChart;
                for (int i = 0; i < 5; i++)
                {
                    for (int j = 0; j < 5; j++)
                    {

                        if (chart.ChartData[i, j].Value.ToString().Trim().Length == 0)
                        {
                            chart.ChartData[i, j].Value = "";
                            Console.Write("***");
                        }
                        else
                        {
                            chart.ChartData[i, j].Value = chart.ChartData[i, j].Value;

                        }

                        Console.WriteLine(chart.ChartData[i, j].Value);
                    }
                    Console.WriteLine("======");
                }
                Console.ReadLine();
            }


Best Regards,
Herman
E-iceblue support team
User avatar

Herman.Yan
 
Posts: 115
Joined: Wed Mar 08, 2023 2:00 am

Mon Apr 03, 2023 4:33 pm

Hi,

I have tried upgrading to the latest spire.Presentation version 8.3.2 but I am still getting the issue.
I was also able to replicate it using the code you've provided after saving the file.
I used this as sample:
sample.zip

Here's the code I used to save the file:

Code: Select all
            Presentation ppt = new Presentation();
            ppt.LoadFromFile(@"sample.pptx");
            if (ppt.Slides[0].Shapes[0] is IChart)
            {
                IChart chart = ppt.Slides[0].Shapes[0] as IChart;
                for (int i = 0; i < 5; i++)
                {
                    for (int j = 0; j < 5; j++)
                    {

                        if (chart.ChartData[i, j].Value.ToString().Trim().Length == 0)
                        {
                            chart.ChartData[i, j].Value = "";
                            Console.Write("***");
                        }
                        else
                        {
                            chart.ChartData[i, j].Value = chart.ChartData[i, j].Value;

                        }

                        Console.WriteLine(chart.ChartData[i, j].Value);
                    }
                    Console.WriteLine("======");
                }
                Console.ReadLine();
                ppt.SaveToFile(@"samplenew.pptx", FileFormat.Pptx2013);
            }


After saving the file, try opening the samplenew.pptx that was saved. Open the chart on slide 1 with null data. Click on Design Tab in powerpoint > Select Data > then try to Switch Row/Column. You will notice that the chart gets broken.

Compare this with the chart in Slide 2 where there is no null data, you can switch rows and columns there.

boncyrus
 
Posts: 20
Joined: Wed Mar 01, 2023 10:01 am

Tue Apr 04, 2023 7:13 am

Hi,

Thanks for your feedback.
I used the following code to create a file and did reproduce the issue you mentioned. I have logged this issue into our tracking system with the ticket SPIREPPT-2221, our Dev team will do further investigation and fixing. Once there is any update, we will keep you informed. Sorry for the inconvenience caused.
Code: Select all
            Presentation presentation = new Presentation();

            RectangleF rect = new RectangleF(40, 100, 550, 320);
            IChart chart = presentation.Slides[0].Shapes.AppendChart(ChartType.ColumnClustered, rect);

            chart.ChartTitle.TextProperties.Text = "test";
            chart.ChartTitle.TextProperties.IsCentered = true;
            chart.ChartTitle.Height = 30;
            chart.HasTitle = true;

            string[,] data = new string[,]
            {
                  {"test","Fiat","Renualt","Benz" },
                  {"January","2","4",null},
                  {"February","2","4","5"},
                  {"March","2","4","5"},
                  {"April","2",null,"5"}
            };

            for (int i = 0; i < data.GetLength(0); i++)
            {
                for (int j = 0; j < data.GetLength(1); j++)
                {
                    if (data[i,j]==null)
                    {
                        chart.ChartData[i, j].Value = "";
                        Console.Write("***");
                    }
                    else
                    {
                        chart.ChartData[i, j].Value = data[i,j];

                    }
                   
                }
            }

            chart.Series.SeriesLabel = chart.ChartData["B1", "D1"];

            chart.Categories.CategoryLabels = chart.ChartData["A2", "A5"];

            chart.Series[0].Values = chart.ChartData["B2", "B5"];
            chart.Series[1].Values = chart.ChartData["C2", "C5"];

            chart.ChartStyle = ChartStyle.Style11;

            chart.OverLap = -50;

            chart.GapWidth = 200;

            presentation.SaveToFile(@"E:\works\day4.4\net\chart2.pptx", FileFormat.Pptx2010);


Best Regards,
Herman
E-iceblue support team
User avatar

Herman.Yan
 
Posts: 115
Joined: Wed Mar 08, 2023 2:00 am

Tue Jun 06, 2023 9:32 am

Hello,

Thanks for your patience.
Glad to inform that we just released Spire.Presentation Pack Hotfix Version:8.6.0 which fixed the issue of SPIREPPT-2221, please download it from the following links to test.
Website link: https://www.e-iceblue.com/Download/down ... t-now.html
Nuget link: https://www.nuget.org/packages/Spire.Presentation/8.6.0

And starting from this version, the code for applying the license key has been changed to
Code: Select all
//Spire.Presentation version 8.6.0 above
Spire.Presentation.License.LicenseProvider.SetLicenseKey("your license key");

Sincerely,
Lisa
E-iceblue support team
User avatar

Lisa.Li
 
Posts: 1261
Joined: Wed Apr 25, 2018 3:20 am

Return to Spire.Presentation