menu

WinForms

  • Code Examples
  • Upgrade Guide
  • User Guide
  • Demos
  • Support
  • Forums
  • Download
Class ChartLegend - WindowsForms API Reference | Syncfusion

    Show / Hide Table of Contents

    Class ChartLegend

    The ChartLegend control represents the rectangular region that in turn contains 1 or more legend items, each of them usually representing a series in the chart.

    Inheritance
    System.Object
    ChartDockControl
    ChartLegend
    Implements
    IChartDockControl
    IChartLegend
    Inherited Members
    ChartDockControl.Behavior
    ChartDockControl.ChartAlignmentChanged
    ChartDockControl.ChartDockChanged
    ChartDockControl.DockingFree
    ChartDockControl.IChartDockControl.add_LocationChanged(EventHandler)
    ChartDockControl.IChartDockControl.add_SizeChanged(EventHandler)
    ChartDockControl.IChartDockControl.add_VisibleChanged(EventHandler)
    ChartDockControl.IChartDockControl.get_Enabled()
    ChartDockControl.IChartDockControl.get_Location()
    ChartDockControl.IChartDockControl.get_Size()
    ChartDockControl.IChartDockControl.remove_LocationChanged(EventHandler)
    ChartDockControl.IChartDockControl.remove_SizeChanged(EventHandler)
    ChartDockControl.IChartDockControl.remove_VisibleChanged(EventHandler)
    ChartDockControl.IChartDockControl.set_Enabled(Boolean)
    ChartDockControl.IChartDockControl.set_Location(Point)
    ChartDockControl.IChartDockControl.set_Size(Size)
    ChartDockControl.IChartDockControl.Visible
    ChartDockControl.LocationChanging
    ChartDockControl.Name
    Namespace: Syncfusion.Windows.Forms.Chart
    Assembly: Syncfusion.Chart.Windows.dll
    Syntax
    public class ChartLegend : ChartDockControl, IChartDockControl, IChartLegend

    Constructors

    ChartLegend()

    Initializes a new instance of the ChartLegend class.

    Declaration
    public ChartLegend()

    ChartLegend(ChartControl)

    Initializes a new instance of the ChartLegend class. For internal use. Do not use this constructor directly.

    Declaration
    public ChartLegend(ChartControl chart)
    Parameters
    Type Name Description
    ChartControl chart

    The chart control aggregating this legend.

    ChartLegend(ChartControl, Boolean)

    Initializes a new instance of the ChartLegend class. For internal use. Do not use this constructor directly.

    Declaration
    public ChartLegend(ChartControl chart, bool isWindowLess)
    Parameters
    Type Name Description
    ChartControl chart

    The chart.

    System.Boolean isWindowLess

    if set to true [is window less].

    Fields

    DefaultName

    The name of default legend.

    Declaration
    public const string DefaultName = ""
    Field Value
    Type
    System.String

    Properties

    Alignment

    Controls the alignment of the Docked Control inside the ChartArea

    Declaration
    public override ChartAlignment Alignment { get; set; }
    Property Value
    Type
    ChartAlignment
    Overrides
    ChartDockControl.Alignment

    Anchor

    Gets or sets the edges of the container to which a control is bound and determines how a control is resized with its parent.

    Declaration
    public override AnchorStyles Anchor { get; set; }
    Property Value
    Type
    System.Windows.Forms.AnchorStyles

    BackColor

    Gets or sets the background color for the control.

    Declaration
    public override Color BackColor { get; set; }
    Property Value
    Type
    System.Drawing.Color

    BackInterior

    Gets or sets back interior of the chart legend.

    Declaration
    [ChartTemplate(ChartTemplateSet.Simple)]
    public BrushInfo BackInterior { get; set; }
    Property Value
    Type
    BrushInfo

    Border

    Gets the line style of the border used by the legend.

    Declaration
    [ChartTemplate(ChartTemplateSet.Content)]
    public LineInfo Border { get; }
    Property Value
    Type
    LineInfo

    ColumnsCount

    Gets or sets the number of the columns to be used in the legend. Default is 1.

    Declaration
    [ChartTemplate(ChartTemplateSet.Simple)]
    public int ColumnsCount { get; set; }
    Property Value
    Type
    System.Int32

    CustomItems

    Gets or sets the list of custom LegendItems.

    Declaration
    public ChartLegendItem[] CustomItems { get; set; }
    Property Value
    Type
    ChartLegendItem[]

    Dock

    Gets or sets which control borders are docked to its parent control and determines how a control is resized with its parent.

    Declaration
    public override DockStyle Dock { get; set; }
    Property Value
    Type
    System.Windows.Forms.DockStyle
    Exceptions
    Type Condition
    System.ComponentModel.InvalidEnumArgumentException

    The value assigned is not one of the System.Windows.Forms.DockStyle values.

    FloatingAutoSize

    Gets or sets a value indicating whether floating the legend's auto size. It indicates whether the legend will automatically position and size itself when floating. Default is true.

    Declaration
    [ChartTemplate(ChartTemplateSet.Simple)]
    public bool FloatingAutoSize { get; set; }
    Property Value
    Type Description
    System.Boolean

    true if [floating auto size]; otherwise, false.

    Font

    Gets or sets the font of the text displayed by the control.

    Declaration
    [ChartTemplate(ChartTemplateSet.Simple)]
    public override Font Font { get; set; }
    Property Value
    Type
    System.Drawing.Font

    IsWindowLess

    Gets or sets a value indicating whether the chart control is working as simple object. If it's true then chart don't uses functional of the control.

    Declaration
    public bool IsWindowLess { get; set; }
    Property Value
    Type
    System.Boolean

    Items

    Gets the items of the legend.

    Declaration
    public ChartLegendItem[] Items { get; }
    Property Value
    Type
    ChartLegendItem[]

    ItemsAlignment

    Gets or sets the alignment of the Legend items. Default is Near.

    Declaration
    [ChartTemplate(ChartTemplateSet.Simple)]
    public StringAlignment ItemsAlignment { get; set; }
    Property Value
    Type
    System.Drawing.StringAlignment

    ItemsShadowColor

    Gets or sets the color for the legend's shadow.

    Declaration
    [ChartTemplate(ChartTemplateSet.Simple)]
    public Color ItemsShadowColor { get; set; }
    Property Value
    Type
    System.Drawing.Color

    ItemsShadowOffset

    Gets or sets the offset of shadow for items on the legend.

    Declaration
    public Size ItemsShadowOffset { get; set; }
    Property Value
    Type
    System.Drawing.Size

    ItemsSize

    Gets or sets the default size of items.

    Declaration
    public Size ItemsSize { get; set; }
    Property Value
    Type
    System.Drawing.Size

    ItemsTextAligment

    Gets or sets the text alignment of the legend item. Default is Center.

    Declaration
    [ChartTemplate(ChartTemplateSet.Simple)]
    public VerticalAlignment ItemsTextAligment { get; set; }
    Property Value
    Type
    VerticalAlignment

    LegendAlignment

    Gets or sets the alignment of legend. Default is Center.

    Declaration
    [Obsolete("Use Alignment property.")]
    [ChartTemplate(ChartTemplateSet.Simple)]
    public ChartAlignment LegendAlignment { get; set; }
    Property Value
    Type
    ChartAlignment

    OnlyColumnsForFloating

    Gets or sets a value indicating whether [only columns for floating]. Specifies if the legend should only layout the items in columns while floating. Default is true.

    Declaration
    [ChartTemplate(ChartTemplateSet.Simple)]
    public bool OnlyColumnsForFloating { get; set; }
    Property Value
    Type Description
    System.Boolean

    true if [only columns for floating]; otherwise, false.

    Orientation

    Gets or sets the orientation of items on the legend. Default is Vertical.

    Declaration
    [ChartTemplate(ChartTemplateSet.Simple)]
    public override ChartOrientation Orientation { get; set; }
    Property Value
    Type
    ChartOrientation
    Overrides
    ChartDockControl.Orientation

    Position

    Gets or sets the legend position.

    Declaration
    [ChartTemplate(ChartTemplateSet.Simple)]
    public override ChartDock Position { get; set; }
    Property Value
    Type
    ChartDock
    Overrides
    ChartDockControl.Position

    RepresentationType

    Gets or sets RepresentationType which specifies how the icon in each legend item should be represented. By default, it renders an icon based on the series type.

    Declaration
    [ChartTemplate(ChartTemplateSet.Simple)]
    public ChartLegendRepresentationType RepresentationType { get; set; }
    Property Value
    Type
    ChartLegendRepresentationType

    RowsCount

    Gets or sets the number of rows to be used in the legend. Default is 1.

    Declaration
    [ChartTemplate(ChartTemplateSet.Simple)]
    public int RowsCount { get; set; }
    Property Value
    Type
    System.Int32

    SetDefSizeForCustom

    Gets or sets a value indicating whether [set def size for custom]. This property is obsolete.

    Declaration
    [Obsolete("This property is obsolete and not used anymore.")]
    public bool SetDefSizeForCustom { get; set; }
    Property Value
    Type Description
    System.Boolean

    true if [set def size for custom]; otherwise, false.

    ShowBorder

    Gets or sets a value indicating whether show the legend border.

    Declaration
    [ChartTemplate(ChartTemplateSet.Simple)]
    public bool ShowBorder { get; set; }
    Property Value
    Type
    System.Boolean

    ShowItemsShadow

    Gets or sets a value indicating whether [show items shadow].

    Declaration
    [ChartTemplate(ChartTemplateSet.Simple)]
    public bool ShowItemsShadow { get; set; }
    Property Value
    Type Description
    System.Boolean

    true if [show items shadow]; otherwise, false.

    ShowSymbol

    Gets or sets a value indicating whether [show symbol]. If true, the exact symbol rendered in the series datapoints will be used to render the icon in the legend as well. This overrides most other settings. Default is false.

    Declaration
    [ChartTemplate(ChartTemplateSet.Simple)]
    public bool ShowSymbol { get; set; }
    Property Value
    Type
    System.Boolean

    Spacing

    Gets or sets the spacing between the element borders and the control

    Declaration
    [ChartTemplate(ChartTemplateSet.Simple)]
    public int Spacing { get; set; }
    Property Value
    Type
    System.Int32

    Style

    Gets or sets the style of the ChartLegend.

    Declaration
    public ChartLegendStyle Style { get; set; }
    Property Value
    Type
    ChartLegendStyle

    TabIndex

    Gets or sets the tab order of the control within its container.

    Declaration
    public int TabIndex { get; set; }
    Property Value
    Type
    System.Int32

    Text

    Gets or sets the text associated with this control.

    Declaration
    [ChartTemplate(ChartTemplateSet.Simple)]
    public override string Text { get; set; }
    Property Value
    Type
    System.String

    TextAlignment

    Gets or sets the alignment of the text. Default is Center.

    Declaration
    [ChartTemplate(ChartTemplateSet.Simple)]
    public StringAlignment TextAlignment { get; set; }
    Property Value
    Type
    System.Drawing.StringAlignment

    TextColor

    Gets or sets the color of the text.

    Declaration
    [Obsolete("Use ForeColor property.")]
    public Color TextColor { get; set; }
    Property Value
    Type Description
    System.Drawing.Color

    The color of the text.

    VisibleCheckBox

    Gets or sets a value indicating whether the checkbox of the legend is visible. If visible, the user can use the checkbox to show/hide the whole series.

    Declaration
    [ChartTemplate(ChartTemplateSet.Simple)]
    public bool VisibleCheckBox { get; set; }
    Property Value
    Type
    System.Boolean

    Methods

    Dispose(Boolean)

    Releases the unmanaged resources used by the System.Windows.Forms.Control and its child controls and optionally releases the managed resources.

    Declaration
    protected override void Dispose(bool disposing)
    Parameters
    Type Name Description
    System.Boolean disposing

    true to release both managed and unmanaged resources; false to release only unmanaged resources.

    GetItemBy(Point)

    Gets the legend item at the specified point.

    Declaration
    public ChartLegendItem GetItemBy(Point pt)
    Parameters
    Type Name Description
    System.Drawing.Point pt

    The point.

    Returns
    Type Description
    ChartLegendItem

    Returns ChartLegendItem.

    GetItemBy(Int32, Int32)

    Gets the legend item at the specified coordinates.

    Declaration
    public ChartLegendItem GetItemBy(int x, int y)
    Parameters
    Type Name Description
    System.Int32 x

    The x.

    System.Int32 y

    The y.

    Returns
    Type Description
    ChartLegendItem

    Returns ChartLegendItem.

    GetMinSize(Graphics)

    Calculates and returns the minimum size required by this legend to fit all display items.

    Declaration
    public Size GetMinSize(Graphics g)
    Parameters
    Type Name Description
    System.Drawing.Graphics g

    Graphics object to be used for metrics.

    Returns
    Type Description
    System.Drawing.Size

    Size required.

    Measure(SizeF)

    Internal method. Please do not call from your code.

    Declaration
    public override SizeF Measure(SizeF size)
    Parameters
    Type Name Description
    System.Drawing.SizeF size

    The Size.

    Returns
    Type Description
    System.Drawing.SizeF

    Returns SizeF.

    Overrides
    ChartDockControl.Measure(SizeF)

    OnCursorChanged(EventArgs)

    Override the System.Windows.Forms.Control.OnCursorChanged(System.EventArgs) method.

    Declaration
    protected override void OnCursorChanged(EventArgs e)
    Parameters
    Type Name Description
    System.EventArgs e

    The EventArgument type args.

    OnDoubleClick(EventArgs)

    Override the OnDoubleClick(EventArgs) method.

    Declaration
    protected override void OnDoubleClick(EventArgs e)
    Parameters
    Type Name Description
    System.EventArgs e

    The EventArgument type args.

    OnLocationChanged(EventArgs)

    Override the System.Windows.Forms.Control.OnLocationChanged(System.EventArgs) method.

    Declaration
    protected override void OnLocationChanged(EventArgs e)
    Parameters
    Type Name Description
    System.EventArgs e

    The EventArgument type args.

    OnMouseDown(MouseEventArgs)

    Override the OnMouseDown(MouseEventArgs) method.

    Declaration
    protected override void OnMouseDown(MouseEventArgs e)
    Parameters
    Type Name Description
    System.Windows.Forms.MouseEventArgs e

    The EventArgument type args.

    Overrides
    Syncfusion.Windows.Forms.Chart.ChartDockControl.OnMouseDown(System.Windows.Forms.MouseEventArgs)

    OnMouseLeave(EventArgs)

    Override the OnMouseLeave(EventArgs) method.

    Declaration
    protected override void OnMouseLeave(EventArgs e)
    Parameters
    Type Name Description
    System.EventArgs e

    The EventArgument type args.

    OnMouseMove(MouseEventArgs)

    Override the OnMouseMove(MouseEventArgs) method.

    Declaration
    protected override void OnMouseMove(MouseEventArgs e)
    Parameters
    Type Name Description
    System.Windows.Forms.MouseEventArgs e

    The EventArgument type args.

    Overrides
    Syncfusion.Windows.Forms.Chart.ChartDockControl.OnMouseMove(System.Windows.Forms.MouseEventArgs)

    OnMouseUp(MouseEventArgs)

    Override the OnMouseUp(MouseEventArgs) method.

    Declaration
    protected override void OnMouseUp(MouseEventArgs e)
    Parameters
    Type Name Description
    System.Windows.Forms.MouseEventArgs e

    The EventArgument type args.

    Overrides
    Syncfusion.Windows.Forms.Chart.ChartDockControl.OnMouseUp(System.Windows.Forms.MouseEventArgs)

    OnPaint(PaintEventArgs)

    Override on the standard method of class control. Event handler to event Paint.

    Declaration
    protected override void OnPaint(PaintEventArgs e)
    Parameters
    Type Name Description
    System.Windows.Forms.PaintEventArgs e

    A System.Windows.Forms.PaintEventArgs that contains the event data.

    OnParentChanged(EventArgs)

    Override the System.Windows.Forms.Control.OnParentChanged(System.EventArgs) method.

    Declaration
    protected override void OnParentChanged(EventArgs e)
    Parameters
    Type Name Description
    System.EventArgs e

    The EventArgument type args.

    OnTextChanged(EventArgs)

    Override the System.Windows.Forms.Control.OnTextChanged(System.EventArgs) method.

    Declaration
    protected override void OnTextChanged(EventArgs e)
    Parameters
    Type Name Description
    System.EventArgs e

    The EventArgument type args.

    Refresh()

    Overrides the System.Windows.Forms.Control.Refresh method.

    Declaration
    public override void Refresh()

    SetEventHandler(LegendFilterItemsEventHandler)

    Sets the callback handler to filter the legend items.

    Declaration
    public void SetEventHandler(LegendFilterItemsEventHandler handler)
    Parameters
    Type Name Description
    LegendFilterItemsEventHandler handler

    The handler.

    Events

    DrawItem

    Fired when a legend item needs to draw. Handle this event to change the drawing of items.

    Declaration
    public event LegendDrawItemEventHandler DrawItem
    Event Type
    Type
    LegendDrawItemEventHandler

    DrawItemText

    Fired when a legend item text needs to draw. Handle this event to change the drawing of items text

    Declaration
    public event LegendDrawItemTextEventHandler DrawItemText
    Event Type
    Type
    LegendDrawItemTextEventHandler

    FilterItems

    Fired when the legend items need to be filtered. Handle this event to change the collection of LegendItems that the legend contains.

    Declaration
    public event LegendFilterItemsEventHandler FilterItems
    Event Type
    Type
    LegendFilterItemsEventHandler

    MinSize

    Fired when the legend's minimum size is to be fixed.

    Declaration
    public event ChartLegendMinSizeEventHandler MinSize
    Event Type
    Type
    ChartLegendMinSizeEventHandler

    Explicit Interface Implementations

    IChartLegend.get_Name()

    Declaration
    string IChartLegend.get_Name()
    Returns
    Type
    System.String

    IChartLegend.set_Name(String)

    Declaration
    void IChartLegend.set_Name(string value)
    Parameters
    Type Name Description
    System.String value

    Implements

    IChartDockControl
    IChartLegend
    Back to top Generated by DocFX
    Copyright © 2001 - 2025 Syncfusion Inc. All Rights Reserved