Legend class

Legend class

Encapsulates the object that represents the chart legend.

Inheritance: LegendChartTextFrameChartFrame

The Legend type exposes the following members:

Properties

PropertyDescription
is_inner_modeIndicates 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.
borderGets the Line.
areaGets the ChartFrame.area.
text_fontGets a ChartFrame.font object of the specified ChartFrame object.
text_optionsGets and sets the options of the text.
fontGets a ChartFrame.font object of the specified ChartFrame object.
auto_scale_fontTrue if the text in the object changes font size when the object size changes. The default value is True.
background_modeGets and sets the display mode of the background
backgroundGets and sets the display mode of the background
is_automatic_sizeIndicates whether the chart frame is automatic sized.
xGets or sets the x coordinate of the upper left corner in units of 1/4000 of the chart area.
yGets or sets the y coordinate of the upper left corner in units of 1/4000 of the chart area.
heightGets or sets the height of frame in units of 1/4000 of the chart area.
widthGets or sets the width of frame in units of 1/4000 of the chart area.
shadowTrue if the frame has a shadow.
shape_propertiesGets the ChartFrame.shape_properties object.
is_default_pos_be_setIndicates whether default position(DefaultX, DefaultY, DefaultWidth and DefaultHeight) are set.
default_xRepresents x of default position
default_yRepresents y of default position
default_widthRepresents width of default position
default_heightRepresents height of default position
is_auto_textIndicates the text is auto generated.
is_deletedIndicates whether this data labels is deleted.
text_horizontal_alignmentGets and sets the text horizontal alignment.
text_vertical_alignmentGets or sets the text vertical alignment of text.
rotation_angleRepresents text rotation angle.
is_automatic_rotationIndicates whether the text of the chart is automatically rotated.
textGets or sets the text of a frame’s title.
linked_sourceGets and sets a reference to the worksheet.
text_directionRepresents text reading order.
reading_orderRepresents text reading order.
direction_typeGets and sets the direction of text.
is_text_wrappedGets or sets a value indicating whether the text is wrapped.
is_resize_shape_to_fit_textGets 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.
positionGets or sets the legend position type.
legend_entriesGets 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.
legend_entries_labelsGets the labels of the legend entries after call Chart.Calculate() method.
is_over_layGets or sets whether other chart elements shall be allowed to overlap this chart element.

Methods

MethodDescription
set_position_autoSet position of the frame to automatic
charactersReturns a Characters object that represents a range of characters within the text.
get_legend_labelsGets the labels of the legend entries after call Chart.Calculate() method.

Example

from aspose.cells import Workbook
from aspose.cells.charts import ChartType, LegendPositionType

workbook = Workbook()
sheet = workbook.worksheets[0]
cells = sheet.cells
cells.get(0, 1).put_value("Income")
cells.get(1, 0).put_value("Company A")
cells.get(2, 0).put_value("Company B")
cells.get(3, 0).put_value("Company C")
cells.get(1, 1).put_value(10000)
cells.get(2, 1).put_value(20000)
cells.get(3, 1).put_value(30000)
chartIndex = sheet.charts.add(ChartType.COLUMN, 9, 9, 21, 15)
chart = sheet.charts[chartIndex]
chart.set_chart_data_range("A1:B4", True)
# Set Legend's width and height
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