Legend 类

定义

表示图表图像的图例。Represents the legend for the chart image.

public ref class Legend : System::Windows::Forms::DataVisualization::Charting::ChartNamedElement
public class Legend : System.Windows.Forms.DataVisualization.Charting.ChartNamedElement
type Legend = class
    inherit ChartNamedElement
Public Class Legend
Inherits ChartNamedElement
继承

注解

类封装Chart控件图例的所有功能, 并使用根Chart对象的Legends集合属性公开。 LegendThe Legend class encapsulates all the functionality of the Chart control's legend, and is exposed using the Legends collection property of the root Chart object.

可以有任意数量的图表图像的图例。There can be any number of legends for a chart image.

图例可以:Legends can:

  • 停靠并对齐。Be docked and aligned.

  • 显示在绘制的图表区的内部或外部。Be displayed inside or outside the plotted chart areas.

  • 自动调整其内容。Automatically fit their contents.

  • 使用预定义的样式, 例如行、列或表。Use a predefined style, such as row, column or table.

  • 使用阴影、渐变颜色和背景图像。Use hatching, gradient colors and background images.

  • 调整大小并放置在图表图像中的任意位置。Be sized and positioned anywhere within the chart image.

图例项由LegendItem对象表示, 它们为默认项或自定义项。Legend items are represented by the LegendItem object, and are either default or custom items. 自定义项不与数据关联, 可以使用CustomItems属性添加、删除和修改自定义项。Custom items are not associated with data, and can be added, deleted and modified using the CustomItems property.

默认项默认情况下自动添加到图例, 是圆环图和饼图的绘图数据点的名称。Default items are by default automatically added to the legend, and are the names of the plotted data points for doughnut and pie charts.

对于所有其他图表类型, 默认项为绘制的数据序列的名称。For all other chart types, the default items are the names of the plotted data series. 每个序列都Legend有一个属性, 该属性定义将使用的图例的名称。Each series has a Legend property that defines the name of the legend that will be used. 如果IsVisibleInLegend将属性设置为false, 则不会为序列创建图例项。A legend item will not be created for a series if the IsVisibleInLegend property is set to false. 可以使用LegendText属性更改这些默认项的文本。The text for these default items can be changed using the LegendText property. 此属性将允许您指定将在运行时替换为其相应值的预定义关键字。This property will allow you to specify predefined keywords that will be replaced by their appropriate values at run-time.

如果您有一个饼图并且您设置了Label该属性, 它还会将图例文本设置为您为标签设置的值。If you have a pie chart and you set the Label property, it will also set the legend text to the value you set for the labels. 如果要将文本设置为其他值, 可以设置LegendText属性。If you want to set the text to a different value, you can set the LegendText property. 在大多数情况下, 您需要将LegendText属性设置为 "#AXISLABEL" 或 "#VALX"。In most cases, you would want to set the LegendText property to "#AXISLABEL" or "#VALX".

图例系列符号是矩形、点或线条。Legend series symbols are rectangles, dots or lines. 符号类型由图表自动设置, 并且取决于绘制的图表类型。The symbol type is set automatically by the chart and depends on the plotted chart type.

默认情况下, 图例文本会自动调整大小。Legend text by default is automatically sized. 可以通过禁用IsTextAutoFit属性来禁用图例文本的自动调整大小。You can disable automatic sizing of legend text by disabling the IsTextAutoFit property. 当此属性设置为false时, 图例文本的大小由图例Font的大小属性确定。When this property is set to false, the size of the legend text is determined by the Size property of the legend Font. 如果该IsTextAutoFit属性已启用, 则AutoFitMinFontSize属性确定在调整大小时图例项可以具有的最小字体大小。If the IsTextAutoFit property is enabled, the AutoFitMinFontSize property determines the minimum font size that a legend item can have when resizing.

TextWrapThreshold属性定义在将文本包装到另一行之前, 可在一行上显示的字符数的限制。The TextWrapThreshold property defines a limit on the number of characters that can be shown on one line before text is wrapped to another line. 如果您不希望在图例中自动换行, 请将TextWrapThreshold属性的值设置为零。If you do not wish to wrap text in the legend, set the value of the TextWrapThreshold property to zero. 默认情况下, 当图例中的整个图例文本不符合时, 文本将被截断。By default, when the entire legend text does not fit in the legend, the text will be truncated. 您可以将图例TextWrapThreshold上的设置为, 以使文本换行, 而不是被截断。You can set the TextWrapThreshold on the legend to get the text to wrap instead of being truncated.

如果图例的内容无法放入给定空间, 则图例项将被截断。If the contents of the legend cannot fit into the given space, legend entries are truncated. 将显示一个省略号, 指示有多个条目超出了图例的空间。An ellipsis is shown to indicate that there are more entries than the legend has space for. 若要防止图例项被截断, 请使用Position属性设置图例的位置和大小。To prevent the legend items from being truncated, set the position and size of the legend using the Position property. 设置图例位置或大小时, 图表不能再自动定位图表中的元素。When setting the legend position or size, the chart can no longer automatically position the elements in the chart. 在某些情况下, 您需要手动定位其他图表元素以实现所需的外观。In some cases, you many need to manually position other chart elements to achieve the desired appearance.

另一种方法是定义自己的单元列, 而不是使用默认图例设置。Another option would be to define your own cell columns instead of using the default legend settings.

Legend对象具有 CellColumn 集合; 每个 CellColumn 对象表示图例中的一个列。The Legend object has a CellColumn Collection; each CellColumn object represents a column in the Legend. 单元列具有MaximumWidthMinimumWidth属性, 可以用来调整列的大小。A cell column has MaximumWidth and MinimumWidth properties that can be used to adjust the size of the columns.

当图例包含许多条目时, InterlacedRows可以使用来提高可读性。When the legend contains many entries, InterlacedRows can be used to improve readability. 当此属性设置为 True 时, 它将显示可以使用InterlacedRowsColor属性设置的背景色。When this property is set to True, it will display a back color that you can set using the InterlacedRowsColor property.

默认情况下, 图例放置在图表的右上角。By default, the legend is positioned in the top-right corner of the chart. 此位置可以使用图例的DockingAlignment属性进行修改。This position can be modified by using the Docking and Alignment properties of the legend. 还可以通过使用DockedToChartArea属性, 将图例与图表区相关联。The legend can also be associated with a chart area by use of the DockedToChartArea property. 此属性指定图例应停靠的图表区的名称。This property specifies the name of the chart area for which the legend should be docked. 此外, IsDockedInsideChartArea属性还可用于在图表区域中显示图例。In addition, the IsDockedInsideChartArea property can be used to display the legend inside a chart area.

IsDockedInsideChartArea设置为 False 时MaximumAutoSize , 属性将定义图例自动定位时可用图表中图例的最大大小 (以百分比表示)。When IsDockedInsideChartArea is set to False, the MaximumAutoSize property defines the maximum size, in percent, of the legend within the available chart when the legend is automatically positioned. 如果在设置停靠属性后要调整图例的宽度或高度, 应设置此属性。This property should be set if you wish to adjust the width or height of the legend after the docking properties have been set.

可以使用CustomizeLegend事件修改图例。The legend can be modified using the CustomizeLegend event.

构造函数

Legend()

初始化 Legend 类的新实例。Initializes a new instance of the Legend class.

Legend(String)

使用指定的图例名称初始化 Legend 类的新实例。Initializes a new instance of the Legend class with the specified legend name.

属性

Alignment

获取或设置图例的对齐方式。Gets or sets the alignment of the legend.

AutoFitMinFontSize

获取或设置可用于图例文本自动调整算法的最小字号。Gets or sets the minimum font size that can be used by the autofitting algorithm for the legend text.

BackColor

获取或设置图例的背景色。Gets or sets the background color of a legend.

BackGradientStyle

获取或设置图例的背景渐变方向。Gets or sets the orientation for the background gradient of a legend. 还确定是否使用渐变。Also determines whether a gradient is used.

BackHatchStyle

获取或设置图例的阴影类型。Gets or sets the hatching style of a legend.

BackImage

获取或设置图例的背景图像。Gets or sets the background image of a legend.

BackImageAlignment

获取或设置用于 Unscaled 绘制模式的背景图像对齐方式。Gets or sets the background image alignment used for the Unscaled drawing mode.

BackImageTransparentColor

获取或设置在绘制背景图像时,将替换为透明色的颜色。Gets or sets a color that will be replaced with a transparent color when the background image is drawn.

BackImageWrapMode

获取或设置图例背景图像的绘制模式。Gets or sets the legend background image drawing mode.

BackSecondaryColor

获取或设置图例背景的辅助颜色。Gets or sets the secondary color of a legend background.

BorderColor

获取或设置图例的边框颜色。Gets or sets the border color of a legend.

BorderDashStyle

获取或设置图例的边框样式。Gets or sets the border style of a legend.

BorderWidth

获取或设置图例的边框宽度。Gets or sets the border width of a legend.

CellColumns

获取包含图例单元格列的集合的 LegendCellColumnCollection 对象。Gets the LegendCellColumnCollection object that contains the collection of cell columns for a legend.

CustomItems

获取用于自定义图例项的 LegendItemsCollection 对象。Gets a LegendItemsCollection object used for custom legend items.

DockedToChartArea

获取或设置图例将停靠于其上的 ChartArea 的名称。Gets or sets the name of the ChartArea where the legend will be docked.

Docking

获取或设置一个确定图例是否是停靠图例的值。Gets or sets a value that determines whether the legend is docked.

Enabled

获取或设置一个值,该值指示该图例是否启用。Gets or sets a value that indicates whether the legend is enabled.

Font

获取或设置用于设置图例字体属性的 Font 对象。Gets or sets a Font object, which is used to set font properties of the legend.

ForeColor

获取或设置图例文本的颜色。Gets or sets the color of the legend text.

HeaderSeparator

获取或设置图例标题的直观分隔符类型。Gets or sets the visual separator type for the legend header.

HeaderSeparatorColor

获取或设置图例标题分隔符的颜色。Gets or sets the color of the separator for the legend header.

InsideChartArea

获取或设置在其中绘制图例的图表区域的名称。Gets or sets the name of the chart area in which the legend is drawn.

InterlacedRows

获取或设置一个指示图列行是否由交错背景色绘制的标志。Gets or sets a flag that indicates whether legend rows will be drawn with interlaced background color.

InterlacedRowsColor

获取或设置图例交替行的背景色。Gets or sets the background color of the legend's interlaced rows.

IsDockedInsideChartArea

获取或设置可指示图例是停靠在图表区域内还是其外的标志。Gets or sets a flag that indicates whether the legend is docked inside or outside the chart area.

IsEquallySpacedItems

获取或设置可指示所有图例项是否均等间距分布的标志。Gets or sets a flag that indicates whether all legend items are equally spaced.

IsTextAutoFit

获取或设置指示图例文本是否自动调整大小的标志。Gets or sets a flag that indicates whether the legend text is automatically sized.

ItemColumnSeparator

获取或设置图例表列的直观分隔符类型。Gets or sets the visual separator type for the legend table columns.

ItemColumnSeparatorColor

获取或设置图例表列分隔符的颜色。Gets or sets the color of the legend table column separator.

ItemColumnSpacing

获取或设置图例表列间距。Gets or sets the legend table column spacing.

LegendItemOrder

获取或设置用于指定图例项显示的顺序。Gets or sets a value that specifies the order in which legend items are displayed. 此属性仅对自动添加到图表序列中的图例项有效;对自定义图例项无效。This property only affects legend items automatically added for the chart series; it has no effect on custom legend items.

LegendStyle

获取或设置图例样式。Gets or sets the style of the legend.

MaximumAutoSize

获取或设置图例的最大大小(以图表区域的百分比形式表示)。Gets or sets the maximum size of the legend, measured as a percentage of the chart area. 此值由自动布局算法使用。This value is used by the automatic layout algorithm.

Name

获取或设置图例的名称。Gets or sets the name of the legend.

Position

获取或设置可用于获取或设置图例位置的 ElementPosition 对象。Gets or sets an ElementPosition object, which can be used to get or set the position of the legend.

ShadowColor

获取或设置图例的阴影颜色。Gets or sets the shadow color of the legend.

ShadowOffset

获取或设置图例的阴影偏移量(以像素为单位)。Gets or sets the shadow offset, in pixels, of the legend.

TableStyle

获取或设置图例表样式。Gets or sets the legend table style.

Tag

获取或设置与此图表元素关联的对象。Gets or sets an object associated with this chart element.

(继承自 ChartElement)
TextWrapThreshold

获取或设置可在文本换行前在图例中连续显示的字符数。Gets or sets the number of characters that can be sequentially displayed in the legend before the text is wrapped.

Title

获取或设置图例标题的文本。Gets or sets the text of the legend title.

TitleAlignment

获取或设置图例标题的对齐方式。Gets or sets the alignment of the legend title.

TitleBackColor

获取或设置图例标题的背景色。Gets or sets the background color of the legend title.

TitleFont

获取或设置图例标题的字体。Gets or sets the font for the legend title.

TitleForeColor

获取或设置图例标题的文本颜色。Gets or sets the text color of the legend title.

TitleSeparator

获取或设置图例标题的直观分隔符类型。Gets or sets the visual separator type for the legend title.

TitleSeparatorColor

获取或设置图例标题分隔符的颜色。Gets or sets the color of the legend title separator.

方法

Dispose()

释放由 ChartElement 占用的资源。Releases the resources used by the ChartElement.

(继承自 ChartElement)
Dispose(Boolean)

释放由 Legend 占用的非托管资源,还可以另外再释放托管资源。Releases the unmanaged resources used by the Legend and optionally releases the managed resources.

Equals(Object)

确定指定的 Object 是否等同于当前的 ChartElementDetermines whether the specified Object is equal to the current ChartElement.

(继承自 ChartElement)
GetHashCode()

返回特定类型的哈希算法。Returns a hash function for a particular type.

(继承自 ChartElement)
GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
ToString()

返回表示当前 Object 的字符串。Returns a string that represents the current Object.

(继承自 ChartElement)

适用于