Interface IOfficeChartLegend
Represents the legend in a chart. Each chart can have only one legend.
Namespace: Syncfusion.OfficeChart
Assembly: Syncfusion.OfficeChart.Base.dll
Syntax
public interface IOfficeChartLegend
Properties
FrameFormat
Gets the IOfficeChartFrameFormat object that represents the formatting settings of the legend.Read-only.
Declaration
IOfficeChartFrameFormat FrameFormat { get; }
Property Value
Type | Description |
---|---|
IOfficeChartFrameFormat |
Examples
//Open a presentation
IPresentation presentation = Presentation.Open("Template.pptx");
//Get the chart from the first slide
IPresentationChart chart = presentation.Slides[0].Charts[0] as IPresentationChart;
//Get the chart legend
IOfficeChartLegend legend = chart.Legend;
//Set the legend border format
legend.FrameFormat.Border.AutoFormat = false;
//Set the legend border auto line color
legend.FrameFormat.Border.IsAutoLineColor = false;
//Set the border line color
legend.FrameFormat.Border.LineColor = System.Drawing.Color.Blue;
//Set the border line pattern
legend.FrameFormat.Border.LinePattern = OfficeChartLinePattern.DashDot;
//Set the legend border line weight
legend.FrameFormat.Border.LineWeight = OfficeChartLineWeight.Wide;
//Save the presentation
presentation.Save("Output.pptx");
//Close the presentation
presentation.Close();
'Open a presentation
Dim presentation__1 As IPresentation = Presentation.Open("Template.pptx")
'Get the chart from the first slide
Dim chart As IPresentationChart = TryCast(presentation__1.Slides(0).Charts(0), IPresentationChart)
'Get the chart legend
Dim legend As IOfficeChartLegend = chart.Legend
'Set the legend border format
legend.FrameFormat.Border.AutoFormat = False
'Set the legend border auto line color
legend.FrameFormat.Border.IsAutoLineColor = False
'Set the border line color
legend.FrameFormat.Border.LineColor = System.Drawing.Color.Blue
'Set the border line pattern
legend.FrameFormat.Border.LinePattern = OfficeChartLinePattern.DashDot
'Set the legend border line weight
legend.FrameFormat.Border.LineWeight = OfficeChartLineWeight.Wide
'Save the presentation
presentation__1.Save("Output.pptx")
'Close the presentation
presentation__1.Close()
IncludeInLayout
Gets or sets a value that indicates the legends are overlapping with chart space or not. Default is true.
Declaration
bool IncludeInLayout { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
|
Examples
//Open a presentation
IPresentation presentation = Presentation.Open("Template.pptx");
//Get the chart from the first slide
IPresentationChart chart = presentation.Slides[0].Charts[0] as IPresentationChart;
//Get the chart legend
IOfficeChartLegend legend = chart.Legend;
//Set the layout inclusion
legend.IncludeInLayout = true;
//Save the presentation
presentation.Save("Output.pptx");
//Close the presentation
presentation.Close();
'Open a presentation
Dim presentation__1 As IPresentation = Presentation.Open("Template.pptx")
'Get the chart from the first slide
Dim chart As IPresentationChart = TryCast(presentation__1.Slides(0).Charts(0), IPresentationChart)
'Get the chart legend
Dim legend As IOfficeChartLegend = chart.Legend
'Set the layout inclusion
legend.IncludeInLayout = True
'Save the presentation
presentation__1.Save("Output.pptx")
'Close the presentation
presentation__1.Close()
IsVerticalLegend
Gets or sets whether the legend is vertical. True if vertical legend (a single column of entries); False if horizontal legend (multiple columns of entries). Manual-sized legends always have this bit set to False.
Declaration
bool IsVerticalLegend { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
Examples
//Open a presentation
IPresentation presentation = Presentation.Open("Template.pptx");
//Get the chart from the first slide
IPresentationChart chart = presentation.Slides[0].Charts[0] as IPresentationChart;
//Get the chart legend
IOfficeChartLegend legend = chart.Legend;
//Set the legend position
legend.Position = OfficeLegendPosition.Left;
//Enable the vertical legend
legend.IsVerticalLegend = true;
//Save the presentation
presentation.Save("Output.pptx");
//Close the presentation
presentation.Close();
'Open a presentation
Dim presentation__1 As IPresentation = Presentation.Open("Template.pptx")
'Get the chart from the first slide
Dim chart As IPresentationChart = TryCast(presentation__1.Slides(0).Charts(0), IPresentationChart)
'Get the chart legend
Dim legend As IOfficeChartLegend = chart.Legend
'Set the legend position
legend.Position = OfficeLegendPosition.Left
'Enable the vertical legend
legend.IsVerticalLegend = True
'Save the presentation
presentation__1.Save("Output.pptx")
'Close the presentation
presentation__1.Close()
Layout
Gets or sets the Layout settings of TextArea
Declaration
IOfficeChartLayout Layout { get; set; }
Property Value
Type | Description |
---|---|
IOfficeChartLayout |
Examples
//Open a presentation
IPresentation presentation = Presentation.Open("Template.pptx");
//Get the chart from the first slide
IPresentationChart chart = presentation.Slides[0].Charts[0] as IPresentationChart;
//Get the chart legend
IOfficeChartLegend legend = chart.Legend;
//Modify the legend layout height
legend.Layout.Height = 100;
//Modify the legend layout height mode
legend.Layout.HeightMode = LayoutModes.factor;
//Modify the legend layout left position
legend.Layout.Left = 100;
//Modify the legend layout left mode
legend.Layout.LeftMode = LayoutModes.factor;
//Modify the legend layout top position
legend.Layout.Top = 100;
//Modify the legend layout top mode
legend.Layout.TopMode = LayoutModes.factor;
//Modify the legend layout width
legend.Layout.Width = 150;
//Modify the legend layout width mode
legend.Layout.WidthMode = LayoutModes.factor;
//Save the presentation
presentation.Save("Output.pptx");
//Close the presentation
presentation.Close();
'Open a presentation
Dim presentation__1 As IPresentation = Presentation.Open("Template.pptx")
'Get the chart from the first slide
Dim chart As IPresentationChart = TryCast(presentation__1.Slides(0).Charts(0), IPresentationChart)
'Get the chart legend
Dim legend As IOfficeChartLegend = chart.Legend
'Modify the legend layout height
legend.Layout.Height = 100
'Modify the legend layout height mode
legend.Layout.HeightMode = LayoutModes.factor
'Modify the legend layout left position
legend.Layout.Left = 100
'Modify the legend layout left mode
legend.Layout.LeftMode = LayoutModes.factor
'Modify the legend layout top position
legend.Layout.Top = 100
'Modify the legend layout top mode
legend.Layout.TopMode = LayoutModes.factor
'Modify the legend layout width
legend.Layout.Width = 150
'Modify the legend layout width mode
legend.Layout.WidthMode = LayoutModes.factor
'Save the presentation
presentation__1.Save("Output.pptx")
'Close the presentation
presentation__1.Close()
LegendEntries
Gets legend entries collection. Read-only.
Declaration
IChartLegendEntries LegendEntries { get; }
Property Value
Type | Description |
---|---|
IChartLegendEntries |
Examples
//Open a presentation
IPresentation presentation = Presentation.Open("Template.pptx");
//Get the chart from the first slide
IPresentationChart chart = presentation.Slides[0].Charts[0] as IPresentationChart;
//Get the chart legend
IOfficeChartLegend legend = chart.Legend;
//Set the text area font weight
legend.TextArea.Bold = true;
//Set the legend text area forecolor
legend.TextArea.Color = OfficeKnownColors.Sky_blue;
//Set the legend text area font name
legend.TextArea.FontName = "Times New Roman";
//Set the legend text area font size
legend.TextArea.Size = 15;
//Modify the legend entry
legend.LegendEntries[0].IsDeleted = true;
//Save the presentation
presentation.Save("Output.pptx");
//Close the presentation
presentation.Close();
'Open a presentation
Dim presentation__1 As IPresentation = Presentation.Open("Template.pptx")
'Get the chart from the first slide
Dim chart As IPresentationChart = TryCast(presentation__1.Slides(0).Charts(0), IPresentationChart)
'Get the chart legend
Dim legend As IOfficeChartLegend = chart.Legend
'Set the text area font weight
legend.TextArea.Bold = True
'Set the legend text area forecolor
legend.TextArea.Color = OfficeKnownColors.Sky_blue
'Set the legend text area font name
legend.TextArea.FontName = "Times New Roman"
'Set the legend text area font size
legend.TextArea.Size = 15
'Modify the legend entry
legend.LegendEntries(0).IsDeleted = True
'Save the presentation
presentation__1.Save("Output.pptx")
'Close the presentation
presentation__1.Close()
Position
Gets or sets the position of the legend on the chart Type: 0 = bottom 1 = corner 2 = top 3 = right 4 = left 7 = not docked or inside the plot area
Declaration
OfficeLegendPosition Position { get; set; }
Property Value
Type | Description |
---|---|
OfficeLegendPosition |
Examples
//Open a presentation
IPresentation presentation = Presentation.Open("Template.pptx");
//Get the chart from the first slide
IPresentationChart chart = presentation.Slides[0].Charts[0] as IPresentationChart;
//Get the chart legend
IOfficeChartLegend legend = chart.Legend;
//Set the legend position
legend.Position = OfficeLegendPosition.Left;
//Save the presentation
presentation.Save("Output.pptx");
//Close the presentation
presentation.Close();
'Open a presentation
Dim presentation__1 As IPresentation = Presentation.Open("Template.pptx")
'Get the chart from the first slide
Dim chart As IPresentationChart = TryCast(presentation__1.Slides(0).Charts(0), IPresentationChart)
'Get the chart legend
Dim legend As IOfficeChartLegend = chart.Legend
'Set the legend position
legend.Position = OfficeLegendPosition.Left
'Save the presentation
presentation__1.Save("Output.pptx")
'Close the presentation
presentation__1.Close()
TextArea
Gets IOfficeChartTextArea object that represents a text area of the legend.Read-only.
Declaration
IOfficeChartTextArea TextArea { get; }
Property Value
Type | Description |
---|---|
IOfficeChartTextArea |
Examples
//Open a presentation
IPresentation presentation = Presentation.Open("Template.pptx");
//Get the chart from the first slide
IPresentationChart chart = presentation.Slides[0].Charts[0] as IPresentationChart;
//Get the chart legend
IOfficeChartLegend legend = chart.Legend;
//Set the text area font weight
legend.TextArea.Bold = true;
//Set the legend text area forecolor
legend.TextArea.Color = OfficeKnownColors.Sky_blue;
//Set the legend text area font name
legend.TextArea.FontName = "Times New Roman";
//Set the legend text area font size
legend.TextArea.Size = 15;
//Set the legend text area' strike through
legend.TextArea.Strikethrough = true;
//Save the presentation
presentation.Save("Output.pptx");
//Close the presentation
presentation.Close();
'Open a presentation
Dim presentation__1 As IPresentation = Presentation.Open("Template.pptx")
'Get the chart from the first slide
Dim chart As IPresentationChart = TryCast(presentation__1.Slides(0).Charts(0), IPresentationChart)
'Get the chart legend
Dim legend As IOfficeChartLegend = chart.Legend
'Set the text area font weight
legend.TextArea.Bold = True
'Set the legend text area forecolor
legend.TextArea.Color = OfficeKnownColors.Sky_blue
'Set the legend text area font name
legend.TextArea.FontName = "Times New Roman"
'Set the legend text area font size
legend.TextArea.Size = 15
'Set the legend text area' strike through
legend.TextArea.Strikethrough = True
'Save the presentation
presentation__1.Save("Output.pptx")
'Close the presentation
presentation__1.Close()
X
Gets or sets X-position of upper-left corner. 1/4000 of chart plot.
Declaration
int X { get; set; }
Property Value
Type | Description |
---|---|
System.Int32 |
Examples
//Open a presentation
IPresentation presentation = Presentation.Open("Template.pptx");
//Get the chart from the first slide
IPresentationChart chart = presentation.Slides[0].Charts[0] as IPresentationChart;
//Get the chart legend
IOfficeChartLegend legend = chart.Legend;
//Set the legend position
legend.Position = OfficeLegendPosition.Top;
//Set the position of legend
legend.X = 120;
legend.Y = 25;
//Save the presentation
presentation.Save("Output.pptx");
//Close the presentation
presentation.Close();
'Open a presentation
Dim presentation__1 As IPresentation = Presentation.Open("Template.pptx")
'Get the chart from the first slide
Dim chart As IPresentationChart = TryCast(presentation__1.Slides(0).Charts(0), IPresentationChart)
'Get the chart legend
Dim legend As IOfficeChartLegend = chart.Legend
'Set the legend position
legend.Position = OfficeLegendPosition.Top
'Set the position of legend
legend.X = 120
legend.Y = 25
'Save the presentation
presentation__1.Save("Output.pptx")
'Close the presentation
presentation__1.Close()
Y
Gets or sets Y-position of upper-left corner. 1/4000 of chart plot.
Declaration
int Y { get; set; }
Property Value
Type | Description |
---|---|
System.Int32 |
Examples
//Open a presentation
IPresentation presentation = Presentation.Open("Template.pptx");
//Get the chart from the first slide
IPresentationChart chart = presentation.Slides[0].Charts[0] as IPresentationChart;
//Get the chart legend
IOfficeChartLegend legend = chart.Legend;
//Set the legend position
legend.Position = OfficeLegendPosition.Top;
//Set the position of legend
legend.X = 120;
legend.Y = 25;
//Save the presentation
presentation.Save("Output.pptx");
//Close the presentation
presentation.Close();
'Open a presentation
Dim presentation__1 As IPresentation = Presentation.Open("Template.pptx")
'Get the chart from the first slide
Dim chart As IPresentationChart = TryCast(presentation__1.Slides(0).Charts(0), IPresentationChart)
'Get the chart legend
Dim legend As IOfficeChartLegend = chart.Legend
'Set the legend position
legend.Position = OfficeLegendPosition.Top
'Set the position of legend
legend.X = 120
legend.Y = 25
'Save the presentation
presentation__1.Save("Output.pptx")
'Close the presentation
presentation__1.Close()
Methods
Clear()
Clears chart legend.
Declaration
void Clear()
Examples
IPresentation presentation = Presentation.Create();
ISlide slide = presentation.Slides.Add(SlideLayoutType.Blank);
//Add chart to the slide with position and size
IPresentationChart chart = slide.Charts.AddChart(100, 10, 500, 300);
//Set chart data - Row1
chart.ChartData.SetValue(1, 2, "Jan");
chart.ChartData.SetValue(1, 3, "Feb");
chart.ChartData.SetValue(1, 4, "March");
//Set chart data - Row2
chart.ChartData.SetValue(2, 1, "2011");
chart.ChartData.SetValue(2, 2, "60");
chart.ChartData.SetValue(2, 3, "70");
chart.ChartData.SetValue(2, 4, "80");
//Set chart data - Row3
chart.ChartData.SetValue(3, 1, "2009");
chart.ChartData.SetValue(3, 2, "80");
chart.ChartData.SetValue(3, 3, "70");
chart.ChartData.SetValue(3, 4, "60");
//Set chart data - Row4
chart.ChartData.SetValue(4, 1, "2010");
chart.ChartData.SetValue(4, 2, "60");
chart.ChartData.SetValue(4, 3, "70");
chart.ChartData.SetValue(4, 4, "80");
//Create a new chart series with the name
IOfficeChartSerie serieJan = chart.Series.Add("Jan");
//Set the data range of chart serie � start row, start column, end row, end column
serieJan.Values = chart.ChartData[2, 2, 4, 2];
//Create a new chart series with the name
IOfficeChartSerie serieFeb = chart.Series.Add("Feb");
//Set the data range of chart serie � start row, start column, end row, end column
serieFeb.Values = chart.ChartData[2, 3, 4, 3];
//Create a new chart series with the name
IOfficeChartSerie serieMarch = chart.Series.Add("March");
//Set the data range of chart series � start row, start column, end row, end column
serieMarch.Values = chart.ChartData[2, 4, 4, 4];
//Get the chart legend
IOfficeChartLegend legend = chart.Legend;
//Set the legend border format
legend.FrameFormat.Border.AutoFormat = false;
//Set the legend border auto line color
legend.FrameFormat.Border.IsAutoLineColor = false;
//Set the border line color
legend.FrameFormat.Border.LineColor = Color.Blue;
//Set the border line pattern
legend.FrameFormat.Border.LinePattern = OfficeChartLinePattern.DashDot;
//Set the legend border line weight
legend.FrameFormat.Border.LineWeight = OfficeChartLineWeight.Wide;
//Reset the legend format
legend.Clear();
//Save the presentation
presentation.Save("Output.pptx");
//Close the presentation
presentation.Close();
Dim presentation__1 As IPresentation = Presentation.Create()
Dim slide As ISlide = presentation__1.Slides.Add(SlideLayoutType.Blank)
'Add chart to the slide with position and size
Dim chart As IPresentationChart = slide.Charts.AddChart(100, 10, 500, 300)
'Set chart data - Row1
chart.ChartData.SetValue(1, 2, "Jan")
chart.ChartData.SetValue(1, 3, "Feb")
chart.ChartData.SetValue(1, 4, "March")
'Set chart data - Row2
chart.ChartData.SetValue(2, 1, "2011")
chart.ChartData.SetValue(2, 2, "60")
chart.ChartData.SetValue(2, 3, "70")
chart.ChartData.SetValue(2, 4, "80")
'Set chart data - Row3
chart.ChartData.SetValue(3, 1, "2009")
chart.ChartData.SetValue(3, 2, "80")
chart.ChartData.SetValue(3, 3, "70")
chart.ChartData.SetValue(3, 4, "60")
'Set chart data - Row4
chart.ChartData.SetValue(4, 1, "2010")
chart.ChartData.SetValue(4, 2, "60")
chart.ChartData.SetValue(4, 3, "70")
chart.ChartData.SetValue(4, 4, "80")
'Create a new chart series with the name
Dim serieJan As IOfficeChartSerie = chart.Series.Add("Jan")
'Set the data range of chart serie � start row, start column, end row, end column
serieJan.Values = chart.ChartData(2, 2, 4, 2)
'Create a new chart series with the name
Dim serieFeb As IOfficeChartSerie = chart.Series.Add("Feb")
'Set the data range of chart serie � start row, start column, end row, end column
serieFeb.Values = chart.ChartData(2, 3, 4, 3)
'Create a new chart series with the name
Dim serieMarch As IOfficeChartSerie = chart.Series.Add("March")
'Set the data range of chart series � start row, start column, end row, end column
serieMarch.Values = chart.ChartData(2, 4, 4, 4)
'Get the chart legend
Dim legend As IOfficeChartLegend = chart.Legend
'Set the legend border format
legend.FrameFormat.Border.AutoFormat = False
'Set the legend border auto line color
legend.FrameFormat.Border.IsAutoLineColor = False
'Set the border line color
legend.FrameFormat.Border.LineColor = Color.Blue
'Set the border line pattern
legend.FrameFormat.Border.LinePattern = OfficeChartLinePattern.DashDot
'Set the legend border line weight
legend.FrameFormat.Border.LineWeight = OfficeChartLineWeight.Wide
'Reset the legend format
legend.Clear()
'Save the presentation
presentation__1.Save("Output.pptx")
'Close the presentation
presentation__1.Close()
Delete()
Deletes chart legend.
Declaration
void Delete()
Examples
IPresentation presentation = Presentation.Create();
ISlide slide = presentation.Slides.Add(SlideLayoutType.Blank);
//Add chart to the slide with position and size
IPresentationChart chart = slide.Charts.AddChart(100, 10, 500, 300);
//Set chart data - Row1
chart.ChartData.SetValue(1, 2, "Jan");
chart.ChartData.SetValue(1, 3, "Feb");
chart.ChartData.SetValue(1, 4, "March");
//Set chart data - Row2
chart.ChartData.SetValue(2, 1, "2011");
chart.ChartData.SetValue(2, 2, "60");
chart.ChartData.SetValue(2, 3, "70");
chart.ChartData.SetValue(2, 4, "80");
//Set chart data - Row3
chart.ChartData.SetValue(3, 1, "2009");
chart.ChartData.SetValue(3, 2, "80");
chart.ChartData.SetValue(3, 3, "70");
chart.ChartData.SetValue(3, 4, "60");
//Set chart data - Row4
chart.ChartData.SetValue(4, 1, "2010");
chart.ChartData.SetValue(4, 2, "60");
chart.ChartData.SetValue(4, 3, "70");
chart.ChartData.SetValue(4, 4, "80");
//Create a new chart series with the name
IOfficeChartSerie serieJan = chart.Series.Add("Jan");
//Set the data range of chart serie � start row, start column, end row, end column
serieJan.Values = chart.ChartData[2, 2, 4, 2];
//Create a new chart series with the name
IOfficeChartSerie serieFeb = chart.Series.Add("Feb");
//Set the data range of chart serie � start row, start column, end row, end column
serieFeb.Values = chart.ChartData[2, 3, 4, 3];
//Create a new chart series with the name
IOfficeChartSerie serieMarch = chart.Series.Add("March");
//Set the data range of chart series � start row, start column, end row, end column
serieMarch.Values = chart.ChartData[2, 4, 4, 4];
//Get the chart legend
IOfficeChartLegend legend = chart.Legend;
//Delete the chart's legend
legend.Delete();
//Save the presentation
presentation.Save("Output.pptx");
//Close the presentation
presentation.Close();
Dim presentation__1 As IPresentation = Presentation.Create()
Dim slide As ISlide = presentation__1.Slides.Add(SlideLayoutType.Blank)
'Add chart to the slide with position and size
Dim chart As IPresentationChart = slide.Charts.AddChart(100, 10, 500, 300)
'Set chart data - Row1
chart.ChartData.SetValue(1, 2, "Jan")
chart.ChartData.SetValue(1, 3, "Feb")
chart.ChartData.SetValue(1, 4, "March")
'Set chart data - Row2
chart.ChartData.SetValue(2, 1, "2011")
chart.ChartData.SetValue(2, 2, "60")
chart.ChartData.SetValue(2, 3, "70")
chart.ChartData.SetValue(2, 4, "80")
'Set chart data - Row3
chart.ChartData.SetValue(3, 1, "2009")
chart.ChartData.SetValue(3, 2, "80")
chart.ChartData.SetValue(3, 3, "70")
chart.ChartData.SetValue(3, 4, "60")
'Set chart data - Row4
chart.ChartData.SetValue(4, 1, "2010")
chart.ChartData.SetValue(4, 2, "60")
chart.ChartData.SetValue(4, 3, "70")
chart.ChartData.SetValue(4, 4, "80")
'Create a new chart series with the name
Dim serieJan As IOfficeChartSerie = chart.Series.Add("Jan")
'Set the data range of chart serie � start row, start column, end row, end column
serieJan.Values = chart.ChartData(2, 2, 4, 2)
'Create a new chart series with the name
Dim serieFeb As IOfficeChartSerie = chart.Series.Add("Feb")
'Set the data range of chart serie � start row, start column, end row, end column
serieFeb.Values = chart.ChartData(2, 3, 4, 3)
'Create a new chart series with the name
Dim serieMarch As IOfficeChartSerie = chart.Series.Add("March")
'Set the data range of chart series � start row, start column, end row, end column
serieMarch.Values = chart.ChartData(2, 4, 4, 4)
'Get the chart legend
Dim legend As IOfficeChartLegend = chart.Legend
'Delete the chart's legend
legend.Delete()
'Save the presentation
presentation__1.Save("Output.pptx")
'Close the presentation
presentation__1.Close()