Legend

Legend class

Encapsulates the object that represents the chart legend.

public class Legend : ChartTextFrame

Properties

Name Description
virtual Area { get; } Gets the area.
virtual AutoScaleFont { get; set; } True if the text in the object changes font size when the object size changes. The default value is True.
Background { get; set; } Gets and sets the display mode of the background
BackgroundMode { get; set; } Gets and sets the display mode of the background
virtual Border { get; } Gets the border.
DefaultHeight { get; } Represents height of default position
DefaultWidth { get; } Represents width of default position
DefaultX { get; } Represents x of default position
DefaultY { get; } Represents y of default position
virtual DirectionType { get; set; } Gets and sets the direction of text.
virtual Font { get; } Gets a Font object of the specified ChartFrame object.
virtual Height { get; set; } Gets or sets the height of frame in units of 1/4000 of the chart area.
virtual IsAutomaticSize { get; set; } Indicates whether the chart frame is automatic sized.
virtual IsAutoText { get; set; } Indicates the text is auto generated.
IsDefaultPosBeSet { get; } Indicates whether default position(DefaultX, DefaultY, DefaultWidth and DefaultHeight) are set.
IsDeleted { get; set; } Indicates whether this data labels is deleted.
IsInnerMode { get; set; } Indicates whether the size of the plot area size includes the tick marks, and the axis labels. False specifies that the size shall determine the size of the plot area, the tick marks, and the axis labels.
IsOverLay { get; set; } Gets or sets whether other chart elements shall be allowed to overlap this chart element.
IsResizeShapeToFitText { get; set; } Gets or sets whether a shape should be auto-fit to fully contain the text described within it. Auto-fitting is when text within a shape is scaled in order to contain all the text inside.
virtual IsTextWrapped { get; set; } Gets or sets a value indicating whether the text is wrapped.
LegendEntries { get; } Gets a collection of all the LegendEntry objects in the specified chart legend. Setting the legend entries of the surface chart is not supported. So it will return null if the chart type is surface chart type.
LegendEntriesLabels { get; } Gets the labels of the legend entries after call Chart.Calculate() method.
virtual LinkedSource { get; set; } Gets and sets a reference to the worksheet.
Position { get; set; } Gets or sets the legend position type.
ReadingOrder { get; set; } Represents text reading order.
RotationAngle { get; set; } Represents text rotation angle.
Shadow { get; set; } True if the frame has a shadow.
ShapeProperties { get; } Gets the ShapeProperties object.
virtual Text { get; set; } Gets or sets the text of a frame’s title.
TextDirection { get; set; } Represents text reading order.
virtual TextFont { get; } Gets a Font object of the specified ChartFrame object.
TextHorizontalAlignment { get; set; } Gets and sets the text horizontal alignment.
TextVerticalAlignment { get; set; } Gets or sets the text vertical alignment of text.
virtual Width { get; set; } Gets or sets the width of frame in units of 1/4000 of the chart area.
virtual X { get; set; } Gets or sets the x coordinate of the upper left corner in units of 1/4000 of the chart area.
virtual Y { get; set; } Gets or sets the y coordinate of the upper left corner in units of 1/4000 of the chart area.

Methods

Name Description
Characters(int, int) Returns a Characters object that represents a range of characters within the text.
virtual SetPositionAuto() Set position of the frame to automatic

Examples

[C#]
   
Workbook workbook = new Workbook();
Worksheet sheet = workbook.Worksheets[0];

Cells cells = sheet.Cells;
cells[0,1].PutValue("Income");
cells[1,0].PutValue("Company A");
cells[2,0].PutValue("Company B");
cells[3,0].PutValue("Company C");
cells[1,1].PutValue(10000);
cells[2,1].PutValue(20000);
cells[3,1].PutValue(30000);
		
int chartIndex = sheet.Charts.Add(ChartType.Column, 9, 9, 21, 15);
Chart chart = sheet.Charts[chartIndex];
chart.SetChartDataRange("A1:B4", true);
//Set Legend's width and height
Legend legend = chart.Legend;

//Legend is at right side of chart by default.
//If the legend is at left or right side of the chart, setting Legend.X property will not take effect.
//If the legend is at top or bottom side of the chart, setting Legend.Y property will not take effect.
legend.Y = 1500;
legend.Width = 50;
legend.Height = 50; 
//Set legend's position
legend.Position = LegendPositionType.Left;

[Visual Basic]

Dim workbook as Workbook = new Workbook()
Dim sheet as Worksheet = workbook.Worksheets(0)

Dim cells as Cells = sheet.Cells
cells(0,1).PutValue("Income")
cells(1,0).PutValue("Company A")
cells(2,0).PutValue("Company B")
cells(3,0).PutValue("Company C")
cells(1,1).PutValue(10000)
cells(2,1).PutValue(20000)
cells(3,1).PutValue(30000)
		
Dim chartIndex as Integer = sheet.Charts.Add(ChartType.Column, 9, 9, 21, 15)

Dim chart as Chart = sheet.Charts(chartIndex)
chart.SetChartDataRange("A1:B4", True);
 
'Set Legend's width and height
Dim legend as Legend = chart.Legend

'Legend is at right side of chart by default.
'If the legend is at left or right side of the chart, setting Legend.X property will not take effect.
'If the legend is at top or bottom side of the chart, setting Legend.Y property will not take effect.
legend.Y = 1500
legend.Width = 50
legend.Height = 50
'Set legend's position
legend.Position = LegendPositionType.Left

See Also