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 May 10, 2022 10:00 am

Hello,

when I try to get chart legend font size from chart.ChartLegend.EntryTextProperties[index].FontHeight is NAN because of this generated pptx from this template gives the wrong font size.
Template legend size is 12 bu generated is 9.

Code: Select all
//Load template presentation
            Presentation templatePresentation = new Presentation();
            //templatePresentation.LoadFromFile("template-overlays.pptx");
            templatePresentation.LoadFromFile("Presentation1.pptx");


            //Create New Presentation
            Spire.Presentation.Presentation presentation = new Spire.Presentation.Presentation();
            presentation.Slides.RemoveAt(0);

            //Get slide from template presentation. index:1
            ISlide cloneSlide = templatePresentation.Slides.ToArray().ElementAtOrDefault(0);

            //---
            //Get Chart                       
            IChart chart = cloneSlide.Shapes.ToArray().FirstOrDefault(x => x.Name == "Chart 14") as IChart;

            var firstLegendFontSize=chart.ChartLegend.EntryTextProperties[0].FontHeight;
            var secondLegendFontSize = chart.ChartLegend.EntryTextProperties[1].FontHeight;

            presentation.Slides.Append(cloneSlide);

            //Save and launch to view the PPTX document.
            presentation.SaveToFile("Test.pptx", Spire.Presentation.FileFormat.Pptx2013);

numankizil
 
Posts: 26
Joined: Tue Nov 09, 2021 8:00 pm

Wed May 11, 2022 5:28 am

Hello,

Thanks for your inquiry.

I tested the file you provided. On my side, the legend font size is 9 in the template pptx which is same as the generated pptx. And regarding get legend font size, you can try the code below.
If I have misunderstood anything, please describe your situation and issue in more detail. Thank you in advance.

Code: Select all
var t = chart.ChartLegend.TextProperties.Paragraphs[0].DefaultCharacterProperties.FontHeight;
Sincerely,
Andy
E-iceblue support team
User avatar

Andy.Zhou
 
Posts: 483
Joined: Mon Mar 29, 2021 3:03 am

Thu May 12, 2022 12:40 pm

Hello,
Thank you for your reply,
Sorry for the wrong explanation When you click to legend wrapping font is 9 it is ok but when we enter in and click to each legend font size should be 9 but it gives 12 .
I found the problem code line when we apply this line it gives 12 without it it is 9 as a template.

Code: Select all
 chart.Categories.CategoryLabels = chart.ChartData["A2", "A" + (categoryCount + 1)]; // this line makes it wrong



Code: Select all
//Load template presentation
            Presentation templatePresentation = new Presentation();
            //templatePresentation.LoadFromFile("template-overlays.pptx");
            templatePresentation.LoadFromFile("legend.pptx");
            Presentation blankPresentation = new Presentation();

            ISlide cloneSlide = templatePresentation.Slides.ToArray().ElementAtOrDefault(0);
            blankPresentation.SetPageSize(templatePresentation.SlideSize.Size.Width, templatePresentation.SlideSize.Size.Height, true);
            blankPresentation.SlideSize.Type = templatePresentation.SlideSize.Type;
            blankPresentation.SlideSize.Size = new SizeF(templatePresentation.SlideSize.Size.Width, templatePresentation.SlideSize.Size.Height);
            blankPresentation.SlideSize.SizeOfPx = new SizeF(templatePresentation.SlideSize.SizeOfPx.Width, templatePresentation.SlideSize.SizeOfPx.Height);
            blankPresentation.SlideSize.Orientation = templatePresentation.SlideSize.Orientation;
            blankPresentation.Slides.Insert(0, cloneSlide);
            var slide = blankPresentation.Slides[0];
            //Create New Presentation
            Spire.Presentation.Presentation presentation = new Spire.Presentation.Presentation();
            presentation.Slides.RemoveAt(0);

            //Get slide from template presentation. index:1
            //ISlide cloneSlide = templatePresentation.Slides.ToArray().ElementAtOrDefault(1);

            //---
            //Get Chart                       
            IChart chart = slide.Shapes.ToArray().FirstOrDefault(x => x.Name == "Chart 14") as IChart;
            int seriesCount = 1;
            int categoryCount = 2;
           
            chart.ChartData.Clear(0, 0, categoryCount + 1, seriesCount + 1);
            var defaultNumberFormat = chart.ChartData[1, 1].NumberFormat;
            chart.ChartData[1, 0].Text = "Category AA";
            chart.ChartData[2, 0].Text = "Category BB";


            chart.ChartData[0, 1].Text = "Serie 1-1";

            chart.ChartData[1, 1].NumberValue = 0.69;
            chart.ChartData[2, 1].NumberValue = 0.68;



            var startIndexAddSeries = chart.Series.Count + 1;
           
            for (int i = startIndexAddSeries; i <= 1; i++)
            {
                chart.Series.Append(chart.ChartData[0, i]);

                chart.Series[i - 1].DataLabels.CategoryNameVisible = chart.Series[0].DataLabels.CategoryNameVisible;
                chart.Series[i - 1].DataLabels.PercentValueVisible = chart.Series[0].DataLabels.PercentValueVisible;
                chart.Series[i - 1].DataLabels.NumberFormat = string.IsNullOrEmpty(chart.Series[0].DataLabels.NumberFormat) ? defaultNumberFormat : chart.Series[0].DataLabels.NumberFormat;
                chart.Series[i - 1].DataLabels.HasDataSource = false;

                chart.Series[i - 1].DataLabels.LabelValueVisible = chart.Series[0].DataLabels.LabelValueVisible;

                chart.Series[i - 1].DataLabels.LeaderLinesVisible = chart.Series[0].DataLabels.LeaderLinesVisible;
                chart.Series[i - 1].DataLabels.TextProperties.Paragraphs[0].DefaultCharacterProperties.FontHeight = chart.Series[0].DataLabels.TextProperties.Paragraphs[0].DefaultCharacterProperties.FontHeight;
            }
            if (chart.Series.Count > seriesCount)
            {
                for (int i = chart.Series.Count - 1; i >= seriesCount; i--)
                {
                    chart.Series.RemoveAt(i);
                }
            }
            chart.Categories.CategoryLabels = chart.ChartData["A2", "A" + (categoryCount + 1)];
            for (int i = 0; i < seriesCount; i++)
            {
                string letter = GetColumnName(i + 1);
                chart.Series[i].Values = chart.ChartData[letter + "2", letter + (categoryCount + 1)];
            }

            presentation.Slides.Append(slide);

            //Save and launch to view the PPTX document.
            presentation.SaveToFile("Test.pptx", Spire.Presentation.FileFormat.Pptx2013);

numankizil
 
Posts: 26
Joined: Tue Nov 09, 2021 8:00 pm

Fri May 13, 2022 11:38 am

Hi,

Thanks for your feedback.

I noticed the problem according to your screenshots. I have logged this issue to our bug tracking system with the ticket SPIREPPT-1953. We will notify you in time when there is any update.
Sincerely,
Andy
E-iceblue support team
User avatar

Andy.Zhou
 
Posts: 483
Joined: Mon Mar 29, 2021 3:03 am

Tue May 17, 2022 10:15 am

Hello,

Any update on this?

numankizil
 
Posts: 26
Joined: Tue Nov 09, 2021 8:00 pm

Wed May 18, 2022 12:59 am

Hello,

Thanks for your following.
Now, We have completed a fix for this issue. It's about to enter the test phase. If all goes well, we will add this fix in the next release and notify you in time.
Sincerely,
Andy
E-iceblue support team
User avatar

Andy.Zhou
 
Posts: 483
Joined: Mon Mar 29, 2021 3:03 am

Mon May 23, 2022 10:10 am

Any updates on this?

majeed_s
 
Posts: 69
Joined: Thu Mar 25, 2021 4:13 pm

Wed May 25, 2022 1:11 am

Hello,

Sorry for the delay.
The fix has passed the test and we will release a new version within this month. I will notify you at that time.
Sincerely,
Andy
E-iceblue support team
User avatar

Andy.Zhou
 
Posts: 483
Joined: Mon Mar 29, 2021 3:03 am

Fri May 27, 2022 9:44 am

Hello,

I have seen that you released a new hotfix :https://www.e-iceblue.com/Download/download-presentation-for-net-now.html

Did you solve this issue with v7.5.3 ?

numankizil
 
Posts: 26
Joined: Tue Nov 09, 2021 8:00 pm

Fri May 27, 2022 10:24 am

numankizil wrote:Hello,

I have seen that you released a new hotfix :https://www.e-iceblue.com/Download/download-presentation-for-net-now.html

Did you solve this issue with v7.5.3 ?


Hi,

Yes we solved the issue SPIREPPT-1953 with the lastest Spire.Presentation v7.5.3. Please download and test it.
webSite link: https://www.e-iceblue.com/Download/down ... t-now.html
Nuget link:https://www.nuget.org/packages/Spire.Presentation/7.5.3
Sincerely,
Andy
E-iceblue support team
User avatar

Andy.Zhou
 
Posts: 483
Joined: Mon Mar 29, 2021 3:03 am

Return to Spire.Presentation