Aspose::Cells::Charts::Legend class

Legend class

Encapsulates the object that represents the chart legend.

class Legend : public Aspose::Cells::Charts::ChartTextFrame

Methods

MethodDescription
Characters(int32_t startIndex, int32_t length)Returns a Characters object that represents a range of characters within the text.
ChartFrame(ChartFrame_Impl* impl)Constructs from an implementation object.
ChartFrame(const ChartFrame& src)Copy constructor.
ChartTextFrame(ChartTextFrame_Impl* impl)Constructs from an implementation object.
ChartTextFrame(const ChartTextFrame& src)Copy constructor.
ChartTextFrame(const ChartFrame& src)Constructs from a parent object.
GetArea()Gets the area.
GetAutoScaleFont()True if the text in the object changes font size when the object size changes. The default value is True.
GetBackgroundMode()Gets and sets the display mode of the background.
GetBorder()Gets the border.
GetDefaultHeight()Represents height of default position.
GetDefaultWidth()Represents width of default position.
GetDefaultX()Represents x of default position.
GetDefaultY()Represents y of default position.
GetDirectionType()Gets and sets the direction of text.
GetFont()Gets a Font object of the specified ChartFrame object.
GetHeight()Gets or sets the height of frame in units of 1/4000 of the chart area.
GetLegendEntries()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.
GetLegendLabels()Gets the labels of the legend entries after call Chart.Calculate() method.
GetLinkedSource()Gets and sets a reference to the worksheet.
GetPosition()Gets or sets the legend position type.
GetReadingOrder()Represents text reading order.
GetRotationAngle()Represents text rotation angle.
GetShadow()True if the frame has a shadow.
GetShapeProperties()Gets the ShapeProperties object.
GetText()Gets or sets the text of a frame’s title.
GetTextHorizontalAlignment()Gets and sets the text horizontal alignment.
GetTextOptions()Gets and sets the options of the text.
GetTextVerticalAlignment()Gets or sets the text vertical alignment of text.
GetWidth()Gets or sets the width of frame in units of 1/4000 of the chart area.
GetX()Gets or sets the x coordinate of the upper left corner in units of 1/4000 of the chart area.
GetY()Gets or sets the y coordinate of the upper left corner in units of 1/4000 of the chart area.
IsAutomaticRotation()Indicates whether the text of the chart is automatically rotated.
IsAutomaticSize()Indicates whether the chart frame is automatic sized.
IsAutoText()Indicates the text is auto generated.
IsDefaultPosBeSet()Indicates whether default position(DefaultX, DefaultY, DefaultWidth and DefaultHeight) are set.
IsDeleted()Indicates whether this data labels is deleted.
IsInnerMode()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.
IsNull() constChecks whether the implementation object is nullptr.
IsOverLay()Gets or sets whether other chart elements shall be allowed to overlap this chart element.
IsResizeShapeToFitText()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.
IsTextWrapped()Gets or sets a value indicating whether the text is wrapped.
Legend(Legend_Impl* impl)Constructs from an implementation object.
Legend(const Legend& src)Copy constructor.
Legend(const ChartTextFrame& src)Constructs from a parent object.
explicit operator bool() constoperator bool()
operator=(const Legend& src)operator=
operator=(const ChartTextFrame& src)operator=
operator=(const ChartFrame& src)operator=
SetAutoScaleFont(bool value)True if the text in the object changes font size when the object size changes. The default value is True.
SetBackgroundMode(BackgroundMode value)Gets and sets the display mode of the background.
SetDirectionType(ChartTextDirectionType value)Gets and sets the direction of text.
SetHeight(int32_t value)Gets or sets the height of frame in units of 1/4000 of the chart area.
SetIsAutomaticSize(bool value)Indicates whether the chart frame is automatic sized.
SetIsAutoText(bool value)Indicates the text is auto generated.
SetIsDeleted(bool value)Indicates whether this data labels is deleted.
SetIsInnerMode(bool value)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.
SetIsOverLay(bool value)Gets or sets whether other chart elements shall be allowed to overlap this chart element.
SetIsResizeShapeToFitText(bool value)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.
SetIsTextWrapped(bool value)Gets or sets a value indicating whether the text is wrapped.
SetLinkedSource(const U16String& value)Gets and sets a reference to the worksheet.
SetLinkedSource(const char16_t* value)Gets and sets a reference to the worksheet.
SetPosition(LegendPositionType value)Gets or sets the legend position type.
SetPositionAuto()Set position of the frame to automatic.
SetReadingOrder(TextDirectionType value)Represents text reading order.
SetRotationAngle(int32_t value)Represents text rotation angle.
SetShadow(bool value)True if the frame has a shadow.
SetText(const U16String& value)Gets or sets the text of a frame’s title.
SetText(const char16_t* value)Gets or sets the text of a frame’s title.
SetTextHorizontalAlignment(TextAlignmentType value)Gets and sets the text horizontal alignment.
SetTextVerticalAlignment(TextAlignmentType value)Gets or sets the text vertical alignment of text.
SetWidth(int32_t value)Gets or sets the width of frame in units of 1/4000 of the chart area.
SetX(int32_t value)Gets or sets the x coordinate of the upper left corner in units of 1/4000 of the chart area.
SetY(int32_t value)Gets or sets the y coordinate of the upper left corner in units of 1/4000 of the chart area.
~ChartFrame()Destructor.
~ChartTextFrame()Destructor.
~Legend()Destructor.

Fields

FieldDescription
_implThe implementation object.

Examples

Aspose::Cells::Startup();
Workbook workbook;
Worksheet sheet = workbook.GetWorksheets().Get(0);

Cells cells = sheet.GetCells();
cells.Get(0, 1).PutValue(u"Income");
cells.Get(1, 0).PutValue(u"Company A");
cells.Get(2, 0).PutValue(u"Company B");
cells.Get(3, 0).PutValue(u"Company C");
cells.Get(1, 1).PutValue(10000);
cells.Get(2, 1).PutValue(20000);
cells.Get(3, 1).PutValue(30000);

int chartIndex = sheet.GetCharts().Add(ChartType::Column, 9, 9, 21, 15);
Chart chart = sheet.GetCharts().Get(chartIndex);
chart.SetChartDataRange(u"A1:B4", true);
//Set Legend's width and height
Legend legend = chart.GetLegend();

//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.SetY(1500);
legend.SetWidth(50);
legend.SetHeight(50);
//Set legend's position
legend.SetPosition(LegendPositionType::Left);

Aspose::Cells::Cleanup();

See Also