Interface IChartLegend
Represents the legend of the chart.
Namespace: Syncfusion.XlsIO
Assembly: Syncfusion.XlsIO.NET.dll
Syntax
public interface IChartLegend
Properties
FrameFormat
Represents IChartFrameFormat object for the legend.
Declaration
IChartFrameFormat FrameFormat { get; }
Property Value
Type |
---|
IChartFrameFormat |
Remarks
To know more about charts refer this link.
Examples
The following code illustrates use of FrameFormat property.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create a worksheet.
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];
sheet.Range["A1"].Text = "Student ID";
sheet.Range["B1"].Text = "Student Name";
sheet.Range["C1"].Text = "Mark(Out of 100)";
sheet.Range["A1:C1"].AutofitColumns();
sheet.Range["A2"].Number = 1;
sheet.Range["A3"].Number = 2;
sheet.Range["A4"].Number = 3;
sheet.Range["A5"].Number = 4;
sheet.Range["A6"].Number = 5;
sheet.Range["B2"].Text = "Andrew";
sheet.Range["B3"].Text = "Marson";
sheet.Range["B4"].Text = "Jack";
sheet.Range["B5"].Text = "Sam";
sheet.Range["B6"].Text = "Breto";
sheet.Range["C2"].Number = 77;
sheet.Range["C3"].Number = 45;
sheet.Range["C4"].Number = 92;
sheet.Range["C5"].Number = 39;
sheet.Range["C6"].Number = 55;
//Create a Chart
IChartShape chart = sheet.Charts.Add();
chart.LeftColumn = 5;
chart.RightColumn = 11;
chart.Name = "Student Sample Chart";
chart.ChartType = ExcelChartType.Cone_Clustered_3D;
chart.DataRange = sheet.Range["B2:C6"];
//sets frame fromat for the legend
chart.Legend.FrameFormat.Border.LineColor = System.Drawing.Color.Orange;
chart.Legend.FrameFormat.Border.LinePattern = ExcelChartLinePattern.DashDotDot;
workbook.SaveAs("Charts.xlsx");
workbook.Close();
}
IncludeInLayout
True to show legend without overlapping the chart. otherwise False. The default is True.
Declaration
bool IncludeInLayout { get; set; }
Property Value
Type |
---|
System.Boolean |
Remarks
Not applicable to Binary files. To know more about charts refer this link.
Examples
The following code illustrates use of IncludeInLayout property.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create a worksheet.
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];
sheet.Range["A1"].Text = "Student ID";
sheet.Range["B1"].Text = "Student Name";
sheet.Range["C1"].Text = "Mark(Out of 100)";
sheet.Range["A1:C1"].AutofitColumns();
sheet.Range["A2"].Number = 1;
sheet.Range["A3"].Number = 2;
sheet.Range["A4"].Number = 3;
sheet.Range["A5"].Number = 4;
sheet.Range["A6"].Number = 5;
sheet.Range["B2"].Text = "Andrew";
sheet.Range["B3"].Text = "Marson";
sheet.Range["B4"].Text = "Jack";
sheet.Range["B5"].Text = "Sam";
sheet.Range["B6"].Text = "Breto";
sheet.Range["C2"].Number = 77;
sheet.Range["C3"].Number = 45;
sheet.Range["C4"].Number = 92;
sheet.Range["C5"].Number = 39;
sheet.Range["C6"].Number = 55;
//Create a Chart
IChartShape chart = sheet.Charts.Add();
chart.LeftColumn = 5;
chart.RightColumn = 11;
chart.Name = "Student Sample Chart";
chart.ChartType = ExcelChartType.Cone_Clustered_3D;
chart.DataRange = sheet.Range["B2:C6"];
//True to show legend without overlapping the chart
IChartLegend chartLegend = chart.Legend;
chartLegend.IncludeInLayout = true;
workbook.SaveAs("Charts.xlsx");
workbook.Close();
}
IsVerticalLegend
True if the legend is vertical. False if the legend is horizontal.
Declaration
bool IsVerticalLegend { get; set; }
Property Value
Type |
---|
System.Boolean |
Remarks
Manual-sized legends always have this bit set to False. For right and left position IsVerticalLegent is true. For Top and Bottom position IsVerticalLegent is false. To know more about charts refer this link.
Examples
The following code illustrates use of IsVerticalLegend property.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create a worksheet.
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];
sheet.Range["A1"].Text = "Student ID";
sheet.Range["B1"].Text = "Student Name";
sheet.Range["C1"].Text = "Mark(Out of 100)";
sheet.Range["A1:C1"].AutofitColumns();
sheet.Range["A2"].Number = 1;
sheet.Range["A3"].Number = 2;
sheet.Range["A4"].Number = 3;
sheet.Range["A5"].Number = 4;
sheet.Range["A6"].Number = 5;
sheet.Range["B2"].Text = "Andrew";
sheet.Range["B3"].Text = "Marson";
sheet.Range["B4"].Text = "Jack";
sheet.Range["B5"].Text = "Sam";
sheet.Range["B6"].Text = "Breto";
sheet.Range["C2"].Number = 77;
sheet.Range["C3"].Number = 45;
sheet.Range["C4"].Number = 92;
sheet.Range["C5"].Number = 39;
sheet.Range["C6"].Number = 55;
//Create a Chart
IChartShape chart = sheet.Charts.Add();
chart.LeftColumn = 5;
chart.RightColumn = 11;
chart.Name = "Student Sample Chart";
chart.ChartType = ExcelChartType.Cone_Clustered_3D;
chart.DataRange = sheet.Range["B2:C6"];
chart.Legend.Position = ExcelLegendPosition.Right;
//True if the legend is vertical
if(chart.Legend.IsVerticalLegend)
{
//Your code here
}
workbook.SaveAs("Charts.xlsx");
workbook.Close();
}
Layout
Gets or sets the layout options of the legend.
Declaration
IChartLayout Layout { get; set; }
Property Value
Type |
---|
IChartLayout |
Remarks
To know more about charts refer this link.
Examples
The following code illustrates use of Layout property.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create a worksheet.
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];
sheet.Range["A1"].Text = "Student ID";
sheet.Range["B1"].Text = "Student Name";
sheet.Range["C1"].Text = "Mark(Out of 100)";
sheet.Range["A1:C1"].AutofitColumns();
sheet.Range["A2"].Number = 1;
sheet.Range["A3"].Number = 2;
sheet.Range["A4"].Number = 3;
sheet.Range["A5"].Number = 4;
sheet.Range["A6"].Number = 5;
sheet.Range["B2"].Text = "Andrew";
sheet.Range["B3"].Text = "Marson";
sheet.Range["B4"].Text = "Jack";
sheet.Range["B5"].Text = "Sam";
sheet.Range["B6"].Text = "Breto";
sheet.Range["C2"].Number = 77;
sheet.Range["C3"].Number = 45;
sheet.Range["C4"].Number = 92;
sheet.Range["C5"].Number = 39;
sheet.Range["C6"].Number = 55;
//Create a Chart
IChartShape chart = sheet.Charts.Add();
chart.LeftColumn = 5;
chart.RightColumn = 11;
chart.Name = "Student Sample Chart";
chart.ChartType = ExcelChartType.Cone_Clustered_3D;
chart.DataRange = sheet.Range["B2:C6"];
//sets the layout options of the legend
chart.Legend.Layout.Height = 100;
chart.Legend.Layout.Width = 60;
workbook.SaveAs("Charts.xlsx");
workbook.Close();
}
LegendEntries
Gets the collection of legend entries. Read-only.
Declaration
IChartLegendEntries LegendEntries { get; }
Property Value
Type |
---|
IChartLegendEntries |
Remarks
To know more about charts refer this link.
Examples
The following code illustrates use of LegendEntries property.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create a worksheet.
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];
sheet.Range["A1"].Text = "Student ID";
sheet.Range["B1"].Text = "Student Name";
sheet.Range["C1"].Text = "Mark(Out of 100)";
sheet.Range["A1:C1"].AutofitColumns();
sheet.Range["A2"].Number = 1;
sheet.Range["A3"].Number = 2;
sheet.Range["A4"].Number = 3;
sheet.Range["A5"].Number = 4;
sheet.Range["A6"].Number = 5;
sheet.Range["B2"].Text = "Andrew";
sheet.Range["B3"].Text = "Marson";
sheet.Range["B4"].Text = "Jack";
sheet.Range["B5"].Text = "Sam";
sheet.Range["B6"].Text = "Breto";
sheet.Range["C2"].Number = 77;
sheet.Range["C3"].Number = 45;
sheet.Range["C4"].Number = 92;
sheet.Range["C5"].Number = 39;
sheet.Range["C6"].Number = 55;
//Create a Chart
IChartShape chart = sheet.Charts.Add();
chart.LeftColumn = 5;
chart.RightColumn = 11;
chart.Name = "Student Sample Chart";
chart.ChartType = ExcelChartType.Cone_Clustered_3D;
chart.DataRange = sheet.Range["B2:C6"];
//Gets the count of legend entries.
int legendEntriesCount = chart.Legend.LegendEntries.Count;
if (legendEntriesCount != 0)
{
//Your code here
}
//Legent entry text area color
chart.Legend.LegendEntries[0].TextArea.Color = ExcelKnownColors.Blue_grey;
workbook.SaveAs("Charts.xlsx");
workbook.Close();
}
Position
Gets or sets the position of legend on the chart. The position values on the chart from ExcelLegendPosition.
Declaration
ExcelLegendPosition Position { get; set; }
Property Value
Type |
---|
ExcelLegendPosition |
Remarks
To know more about charts refer this link.
Examples
The following code illustrates use of Position property.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create a worksheet.
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];
sheet.Range["A1"].Text = "Student ID";
sheet.Range["B1"].Text = "Student Name";
sheet.Range["C1"].Text = "Mark(Out of 100)";
sheet.Range["A1:C1"].AutofitColumns();
sheet.Range["A2"].Number = 1;
sheet.Range["A3"].Number = 2;
sheet.Range["A4"].Number = 3;
sheet.Range["A5"].Number = 4;
sheet.Range["A6"].Number = 5;
sheet.Range["B2"].Text = "Andrew";
sheet.Range["B3"].Text = "Marson";
sheet.Range["B4"].Text = "Jack";
sheet.Range["B5"].Text = "Sam";
sheet.Range["B6"].Text = "Breto";
sheet.Range["C2"].Number = 77;
sheet.Range["C3"].Number = 45;
sheet.Range["C4"].Number = 92;
sheet.Range["C5"].Number = 39;
sheet.Range["C6"].Number = 55;
//Create a Chart
IChartShape chart = sheet.Charts.Add();
chart.LeftColumn = 5;
chart.RightColumn = 11;
chart.Name = "Student Sample Chart";
chart.ChartType = ExcelChartType.Cone_Clustered_3D;
chart.DataRange = sheet.Range["B2:C6"];
//sets the position of legend on the chart.
chart.Legend.Position = ExcelLegendPosition.Top;
workbook.SaveAs("Charts.xlsx");
workbook.Close();
}
TextArea
Gets the text area of the legend. Read-only.
Declaration
IChartTextArea TextArea { get; }
Property Value
Type |
---|
IChartTextArea |
Remarks
To know more about charts refer this link.
Examples
The following code illustrates use of TextArea property.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create a worksheet.
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];
sheet.Range["A1"].Text = "Student ID";
sheet.Range["B1"].Text = "Student Name";
sheet.Range["C1"].Text = "Mark(Out of 100)";
sheet.Range["A1:C1"].AutofitColumns();
sheet.Range["A2"].Number = 1;
sheet.Range["A3"].Number = 2;
sheet.Range["A4"].Number = 3;
sheet.Range["A5"].Number = 4;
sheet.Range["A6"].Number = 5;
sheet.Range["B2"].Text = "Andrew";
sheet.Range["B3"].Text = "Marson";
sheet.Range["B4"].Text = "Jack";
sheet.Range["B5"].Text = "Sam";
sheet.Range["B6"].Text = "Breto";
sheet.Range["C2"].Number = 77;
sheet.Range["C3"].Number = 45;
sheet.Range["C4"].Number = 92;
sheet.Range["C5"].Number = 39;
sheet.Range["C6"].Number = 55;
//Create a Chart
IChartShape chart = sheet.Charts.Add();
chart.LeftColumn = 5;
chart.RightColumn = 11;
chart.Name = "Student Sample Chart";
chart.ChartType = ExcelChartType.Cone_Clustered_3D;
chart.DataRange = sheet.Range["B2:C6"];
//sets text area for the legend
chart.Legend.TextArea.Color = ExcelKnownColors.Blue_grey;
chart.Legend.TextArea.Size = 10;
chart.Legend.TextArea.FontName = "Bernard MT Condensed";
workbook.SaveAs("Charts.xlsx");
workbook.Close();
}
X
Gets the X co-ordinate of upper-left corner of the legend. 1/4000 of chart plot.
Declaration
int X { get; set; }
Property Value
Type |
---|
System.Int32 |
Remarks
To know more about charts refer this link.
Examples
The following code illustrates use of X co-ordinate of upper-left corner of the legend.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create a worksheet.
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];
sheet.Range["A1"].Text = "Student ID";
sheet.Range["B1"].Text = "Student Name";
sheet.Range["C1"].Text = "Mark(Out of 100)";
sheet.Range["A1:C1"].AutofitColumns();
sheet.Range["A2"].Number = 1;
sheet.Range["A3"].Number = 2;
sheet.Range["A4"].Number = 3;
sheet.Range["A5"].Number = 4;
sheet.Range["A6"].Number = 5;
sheet.Range["B2"].Text = "Andrew";
sheet.Range["B3"].Text = "Marson";
sheet.Range["B4"].Text = "Jack";
sheet.Range["B5"].Text = "Sam";
sheet.Range["B6"].Text = "Breto";
sheet.Range["C2"].Number = 77;
sheet.Range["C3"].Number = 45;
sheet.Range["C4"].Number = 92;
sheet.Range["C5"].Number = 39;
sheet.Range["C6"].Number = 55;
//Create a Chart
IChartShape chart = sheet.Charts.Add();
chart.LeftColumn = 5;
chart.RightColumn = 11;
chart.Name = "Student Sample Chart";
chart.ChartType = ExcelChartType.Cone_Clustered_3D;
chart.DataRange = sheet.Range["B2:C6"];
//X co-ordinate of upper-left corner of the legend
chart.Legend.X = -80;
chart.Legend.Y = 30;
workbook.SaveAs("Charts.xlsx");
workbook.Close();
}
Y
Gets the Y co-ordinate of upper-left corner of the legend. 1/4000 of chart plot.
Declaration
int Y { get; set; }
Property Value
Type |
---|
System.Int32 |
Remarks
To know more about charts refer this link.
Examples
The following code illustrates use of Y co-ordinate of upper-left corner of the legend.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create a worksheet.
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];
sheet.Range["A1"].Text = "Student ID";
sheet.Range["B1"].Text = "Student Name";
sheet.Range["C1"].Text = "Mark(Out of 100)";
sheet.Range["A1:C1"].AutofitColumns();
sheet.Range["A2"].Number = 1;
sheet.Range["A3"].Number = 2;
sheet.Range["A4"].Number = 3;
sheet.Range["A5"].Number = 4;
sheet.Range["A6"].Number = 5;
sheet.Range["B2"].Text = "Andrew";
sheet.Range["B3"].Text = "Marson";
sheet.Range["B4"].Text = "Jack";
sheet.Range["B5"].Text = "Sam";
sheet.Range["B6"].Text = "Breto";
sheet.Range["C2"].Number = 77;
sheet.Range["C3"].Number = 45;
sheet.Range["C4"].Number = 92;
sheet.Range["C5"].Number = 39;
sheet.Range["C6"].Number = 55;
//Create a Chart
IChartShape chart = sheet.Charts.Add();
chart.LeftColumn = 5;
chart.RightColumn = 11;
chart.Name = "Student Sample Chart";
chart.ChartType = ExcelChartType.Cone_Clustered_3D;
chart.DataRange = sheet.Range["B2:C6"];
//Y co-ordinate of upper-left corner of the legend
chart.Legend.Y = 30;
chart.Legend.X = -80;
workbook.SaveAs("Charts.xlsx");
workbook.Close();
}
Methods
Clear()
Clears the chart legend.
Declaration
void Clear()
Remarks
To know more about charts refer this link.
Examples
The following code illustrates how to use the Clear method for legend of chart.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create a worksheet.
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Open("Sample.xlsx");
IWorksheet sheet = workbook.Worksheets[0];
//Clears the legend of chart
sheet.Charts[0].Legend.Clear();
workbook.SaveAs("Charts.xlsx");
workbook.Close();
}
Delete()
Deletes the chart legend.
Declaration
void Delete()
Remarks
To know more about charts refer this link.
Examples
The following code illustrates how to use the Delete method for legend of chart.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create a worksheet.
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Open("Sample.xlsx");
IWorksheet sheet = workbook.Worksheets[0];
//Delete the legend of chart
sheet.Charts[0].Legend.Delete();
workbook.SaveAs("Charts.xlsx");
workbook.Close();
}