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.

Thu Feb 22, 2018 1:13 pm

Hi,

I have couple of questions regarding Legend style:

1. How to change Legend's box Border color?
2. How to change Font size of Legend items?
3. Is there any way to retrieve Legend width,height at runtime , currently it is NaN?

Regards

Stecya
 
Posts: 27
Joined: Wed Jan 10, 2018 2:36 pm

Fri Feb 23, 2018 7:04 am

Hello,

Thanks for your inquiry. The following is answer to your questions.
1. How to change Legend's box Border color?
Code: Select all
chart.ChartLegend.Line.FillFormat.SolidFillColor.Color = Color.Red;

2. How to change Font size of Legend items?
Code: Select all
for (int i = 0; i < chart.ChartLegend.EntryTextProperties.Length; i++)
                    {
                        chart.ChartLegend.EntryTextProperties[i].FontHeight = 20;
                   }

3. Is there any way to retrieve Legend width,height at runtime , currently it is NaN?
Please share the document you were trying.

Thanks,
Gary
E-iceblue support team
User avatar

Gary.zhang
 
Posts: 1380
Joined: Thu Apr 04, 2013 1:30 am

Fri Feb 23, 2018 11:36 am

Thanks for answer.
- Point 1 and 2 is working
- Point 3 , please check code snippet

Code: Select all
        static void Main(string[] args)
        {

            var presentation = new Presentation();
            var slide = presentation.Slides[0];

            var chart = slide.Shapes.AppendChart(ChartType.ScatterStraightLinesAndMarkers, new RectangleF(50, 50, 500, 500), false);

            chart.ChartLegend.Position = ChartLegendPositionType.TopRight;
            chart.ChartLegend.Top = 100;
            chart.ChartLegend.IsOverlay = true;
            chart.ChartLegend.Fill.FillType = FillFormatType.Solid;
            chart.ChartLegend.Fill.SolidColor.Color = Color.White;

            chart.ChartLegend.Line.FillFormat.FillType = FillFormatType.Solid;
            chart.ChartLegend.Line.FillFormat.SolidFillColor.Color = Color.Blue;


            int count = 3;

            chart.Series.SeriesLabel = chart.ChartData[0, 0, 0, count - 1];

            for (int i = 0; i < count; i++)
            {
                chart.ChartData[0, i].Value = "Series" + i;

                for (var j = 0; j < 10; j++)
                {
                    chart.ChartData[j + 1, i].Value = i;
                    chart.ChartData[j + 1, count + i].Value = i + j + count;
                }

                chart.Series[i].YValues = chart.ChartData[1, i, 10, i];
                chart.Series[i].XValues = chart.ChartData[1, count + i, 10, count + i];
            }

            for (int i = 0; i < chart.ChartLegend.EntryTextProperties.Length; i++)
            {
                chart.ChartLegend.EntryTextProperties[i].FontHeight = 10;
            }

            var width = chart.ChartLegend.Width; // <--------------- NaN here

            presentation.SaveToFile("D://test.pptx", FileFormat.Pptx2013);

            Process.Start("D://test.pptx");
        }

Stecya
 
Posts: 27
Joined: Wed Jan 10, 2018 2:36 pm

Sat Feb 24, 2018 8:19 am

Hello,

Thanks for your feedback.
I indeed noticed the NaN behavior on my side. And after an investigation, i found that the phenomenon is correct. In fact, chart legend doesn't have an initial width. To verify it, you could use MS Presentation to create a sample ppt file with a chart, and you will find there is no information about ChartLegend width after parsing the sample ppt file. Our Spire.Presentation is based on MS Presentation standard. Thus, you got the NaN of ChartLegend width using our Spire.Presentation. In addition, if you manually change the legend width in MS Presentation, you will see the related information after parsing, meanwhile, you can get the value (not NaN) of the chart legend width using our Spire.
Please feel free to contact us for any confusion.

Sincerely,
Nina
E-iceblue support team
User avatar

Nina.Tang
 
Posts: 1187
Joined: Tue Sep 27, 2016 1:06 am

Return to Spire.Presentation