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 May 13, 2024 7:25 pm

Hi,
I am trying to generate a chart with 1 series and several categories starting from a template, erasing the data then populating it back to the presentation.

Usually this method works just fine, however I noticed a strange behaviour when applying this to a single series output: it seems that categories are tracked in the legend instead of the series.

I am linking a simple sample here (wetransfer link since it's a bit bigger than expected) that produces 2 output: out.pptx with 1 single series and out2.pptx with 2 series (from 2 above the legend is fine).

You may notice that we get categories in the legend instead of series in the case of out.pptx. Even stranger, if you check on the windows preview of the file, the preview will show the expected series, while when you open it you will see categories.

https://we.tl/t-pPklbKqoVA

Anything wrong in what I am doing?
thanks,
Andrea

andreacalvi
 
Posts: 10
Joined: Tue Jul 11, 2023 11:02 am

Tue May 14, 2024 7:33 am

Hi,

Thank you for your message.
Please add the below code when creating a single series chart. I've tested this on my end and it displays the legend correctly. If there's still any issue, feel free to come back with more questions or feedback.

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

Sincerely,
Doris
E-iceblue support team
User avatar

Doris.Liu
 
Posts: 186
Joined: Mon Nov 07, 2022 8:10 am

Fri May 17, 2024 3:22 pm

Hi,
I made suggested changes and they work fine for most of the charts I have.
However, there's still an issue with this one that I previously linked in this post

graph-data-selection-gets-cleared-t12847.html

If I add that line, data is now shown anymore.
I do not add it, I see there's an issue with the legend values (not updating with respect of the actual data)

Here's sample code with template

https://we.tl/t-z0YBo37I5J

Thanks,
Regards,
Andrea

andreacalvi
 
Posts: 10
Joined: Tue Jul 11, 2023 11:02 am

Mon May 20, 2024 6:27 am

Hi,

Sorry to reply late for weekend and thanks for your feedback and further inquiry.
Based on the information you provided, I have reproduced your issue and have logged it in our bug tracking system as SPIREPPT-2520. Our dev team will investigate and fix this issue further. Once it's fixed, we will update you ASAP. Sorry for inconvenience caused.

Sincerely,
Doris
E-iceblue support team
User avatar

Doris.Liu
 
Posts: 186
Joined: Mon Nov 07, 2022 8:10 am

Tue May 21, 2024 5:35 am

Thank you!
I found 2 more examples where adding series label causes issues.
test1.pptx is changing chart colors I believe because there are 2 datapoints defined in the chart that disappear as soon as i set series labels



Code: Select all
            Presentation ppt = new Presentation();
            ppt.LoadFromFile(@"test.pptx");
            var finalPpt = new Presentation();
            finalPpt.Slides.RemoveAt(0);
            finalPpt.SlideSize.Type = ppt.SlideSize.Type;
            var generatedSlide = ppt.Slides[2];
            var chart = generatedSlide.Shapes.ToArray().FirstOrDefault(s => s.Name == "Chart 15") as IChart;

            var targetSeriesCount = 1;
            var targetCategoriesCount = 2;

            chart.ChartData.Clear(0, 0, chart.Series.Count + 1, chart.Categories.Count + 1);
            chart.ChartData[0, 1].Text = "Sales";
            chart.ChartData[1, 0].Text = "a";
            chart.ChartData[2, 0].Text = "b";

            chart.ChartData[1, 1].NumberValue = 6.1;
            chart.ChartData[2, 1].NumberValue = 5.2;

            if (chart.Series.Count > targetSeriesCount)
            {
                for (int i = chart.Series.Count - 1; i >= targetSeriesCount; i--)
                {
                    chart.Series.RemoveAt(i);
                }
            }

            chart.Categories.CategoryLabels = chart.ChartData["A2", "A" + (targetCategoriesCount + 1)];
            chart.Series.SeriesLabel = chart.ChartData["B1", "B1"];
            chart.Series[0].Values = chart.ChartData["B2", "B" + (targetCategoriesCount + 1)];

            finalPpt.Slides.Append(generatedSlide);

            finalPpt.SaveToFile(@"C:\temp\out.pptx", FileFormat.Pptx2013);



Also attaching test2.pptx which is a scatterMarks chart: add that line breaks and corrupts the output. Should this be used only for chart type other than scattermarks?

https://we.tl/t-WyI6QWunxP

Thanks!
Regards,
Andrea

andreacalvi
 
Posts: 10
Joined: Tue Jul 11, 2023 11:02 am

Tue May 21, 2024 10:04 am

Hi Andrea,

Thank you so much for your further information.
I've logged both of these issues into our bug tracking system as well(SPIREPPT-2523 and SPIREPPT-2524), and we'll get back to you as soon as our devs have investigated the results or fixed them!

Sincerely,
Doris
E-iceblue support team
User avatar

Doris.Liu
 
Posts: 186
Joined: Mon Nov 07, 2022 8:10 am

Return to Spire.Presentation

cron