Class Legend

Class Legend

Namespace: Aspose.Cells.Charts
Assembly: Aspose.Cells.dll (25.2.0)

封装表示图表图例的对象。

public class Legend : ChartTextFrame

继承

objectChartFrameChartTextFrameLegend

继承成员

ChartTextFrame.m_IsAutoText, ChartTextFrame.m_deleted, ChartTextFrame.horizontal, ChartTextFrame.vertical, ChartTextFrame.rotation, ChartTextFrame.m_CharsList, ChartTextFrame.Characters(int, int), ChartTextFrame.IsAutoText, ChartTextFrame.IsDeleted, ChartTextFrame.TextHorizontalAlignment, ChartTextFrame.TextVerticalAlignment, ChartTextFrame.RotationAngle, ChartTextFrame.IsAutomaticRotation, ChartTextFrame.Text, ChartTextFrame.LinkedSource, ChartTextFrame.ReadingOrder, ChartTextFrame.DirectionType, ChartTextFrame.IsTextWrapped, ChartTextFrame.IsResizeShapeToFitText, ChartFrame.m_IsAutoXPos, ChartFrame.m_IsAutoYPos, ChartFrame.m_IsOffsetPosBeSet, ChartFrame.m_fontIndex, ChartFrame.m_AutoScaleFont, ChartFrame.m_BackgroundMode, ChartFrame.m_isAutoSize, ChartFrame.SetPositionAuto(), ChartFrame.IsInnerMode, ChartFrame.Border, ChartFrame.Area, ChartFrame.TextOptions, ChartFrame.Font, ChartFrame.AutoScaleFont, ChartFrame.BackgroundMode, ChartFrame.IsAutomaticSize, ChartFrame.X, ChartFrame.Y, ChartFrame.Height, ChartFrame.Width, ChartFrame.Shadow, ChartFrame.ShapeProperties, ChartFrame.IsDefaultPosBeSet, ChartFrame.DefaultX, ChartFrame.DefaultY, ChartFrame.DefaultWidth, ChartFrame.DefaultHeight, object.GetType(), object.MemberwiseClone(), object.ToString(), object.Equals(object?), object.Equals(object?, object?), object.ReferenceEquals(object?, object?), object.GetHashCode()

示例

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

Cells cells = sheet.Cells;
cells[0,1].PutValue("收入");
cells[1,0].PutValue("公司 A");
cells[2,0].PutValue("公司 B");
cells[3,0].PutValue("公司 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);
//设置图例的宽度和高度
Legend legend = chart.Legend;

//图例默认位于图表的右侧。
//如果图例位于图表的左侧或右侧,设置 Legend.X 属性将无效。
//如果图例位于图表的顶部或底部,设置 Legend.Y 属性将无效。
legend.Y = 1500;
legend.Width = 50;
legend.Height = 50; 
//设置图例的位置
legend.Position = LegendPositionType.Left;
Dim workbook as Workbook = new Workbook()
Dim sheet as Worksheet = workbook.Worksheets(0)

Dim cells as Cells = sheet.Cells
cells(0,1).PutValue("收入")
cells(1,0).PutValue("公司 A")
cells(2,0).PutValue("公司 B")
cells(3,0).PutValue("公司 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);

'设置图例的宽度和高度
Dim legend as Legend = chart.Legend

'图例默认位于图表的右侧。
'如果图例位于图表的左侧或右侧,设置 Legend.X 属性将无效。
'如果图例位于图表的顶部或底部,设置 Legend.Y 属性将无效。
legend.Y = 1500
legend.Width = 50
legend.Height = 50
'设置图例的位置
legend.Position = LegendPositionType.Left

属性

IsOverLay

获取或设置是否在不重叠图表的情况下显示图例。

public bool IsOverLay { get; set; }

属性值

bool

LegendEntries

获取指定图表图例中所有 LegendEntry 对象的集合。 不支持设置表面图表的图例项。 因此,如果图表类型为表面图表类型,则返回 null。

public LegendEntryCollection LegendEntries { get; }

属性值

LegendEntryCollection

Position

获取或设置图例位置类型。

public LegendPositionType Position { get; set; }

属性值

LegendPositionType

备注


默认位置在右侧。
如果图例位于图表的左侧或右侧,设置 Legend.X 属性将无效。
如果图例位于图表的顶部或底部,设置 Legend.Y 属性将无效。

方法

GetLegendLabels()

获取调用 Chart.Calculate() 方法后图例项的标签。

public string[] GetLegendLabels()

返回

string[]

 中文