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: 23
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: 406
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: 23
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: 406
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: 23
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: 406
Joined: Mon Nov 07, 2022 8:10 am

Wed Jun 19, 2024 8:50 am

Hi,

Thank you for your patience.
After further investigation of the issues SPIREPPT-2523 and SPIREPPT-2524, our dev team found that setting the Label of a Series will refresh the data of that Series. To prevent the format from changing, please add the line of code "chart.Series.KeepSeriesFormat = true;". This will ensure that the style remains unchanged.

You can refer to the following code snippet for specifics. If you have any further questions, please feel free to contact us at any time.

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

    var targetSeriesCount = 1;
    var targetCategoriesCount = 6;

    chart.ChartData.Clear(0, 0, chart.Series.Count + 1, chart.Categories.Count + 1);
    Double[] xdata = new Double[] { 2.7, 8.9, 10.0, 12.4, 13.4, 15.1, 16.0 };
    Double[] ydata = new Double[] { 3.2, 15.3, 6.7, 8, 9, 10, 12 };

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

    chart.Categories.CategoryLabels = chart.ChartData["C2", "C" + (targetCategoriesCount + 1)];
// Please add this line
    chart.Series.KeepSeriesFormat = true;
    chart.Series.SeriesLabel = chart.ChartData["B1", "B1"];
    chart.Series[0].XValues = chart.ChartData["A2", "A" + (targetCategoriesCount + 1)];
    chart.Series[0].YValues = chart.ChartData["B2", "B" + (targetCategoriesCount + 1)];

    finalPpt.Slides.Append(generatedSlide);
    finalPpt.SaveToFile(@"sactter_out.pptx", FileFormat.Pptx2013);


Sincerely,
Doris
E-iceblue support team
User avatar

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

Thu Jun 27, 2024 7:45 am

Hi, thanks it worked fine and I can produce the output with no corrupted data.
However, the values in the legend do not reflect the actual graph values. I have to manually refresh them from ppt then it works with the right min and max provided in the data.

(see attachment: I have no idea where those 2049,11 and 52,57 come from)

thanks
Andrea

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

Mon Jul 01, 2024 9:15 am

Hi,

Thank you for your feedback.
This issue was previously mentioned in another post and has been logged in our bug system with the number SPIREPPT-2520. I apologize that the development team has not yet found a solution. However, I have reminded them of this, and I will provide you with an update as soon as a solution is found.

Sincerely,
Doris
E-iceblue support team
User avatar

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

Return to Spire.Presentation