2D Chart for WinForms | ComponentOne
Chart for WinForms Task-Based Help / Displaying both the Chart Legend and Chart Header
In This Topic
    Displaying both the Chart Legend and Chart Header
    In This Topic

    Both the Header and Legend have Compass and Location properties, and you can use one or both of these properties to change the position. The Compass property can be set to North, South, East, or West through the ComapssEnum. By default, the Header and Legend will be centered within the Compass area. The Location property can be set to a System.Drawing.Point, which accepts x and y coordinates. Both the x and y coordinates can be set to -1 to use automatic positioning.

    Displaying the Header

    The following example positions your chart header at the top. The point coordinates can be adjusted to fine tune the position:

    To write code in Visual Basic

    Visual Basic
    Copy Code
    c1Chart1.Header.Text = "My Chart Header"
    c1Chart1.Header.Compass = C1.Win.C1Chart.CompassEnum.North
    c1Chart1.Header.Location = New Point(-1, -1)
    c1Chart1.Header.Visible = True
    

    To write code in C#

    C#
    Copy Code
    this.c1Chart1.Header.Text = "My Chart Header";
    this.c1Chart1.Header.Compass = C1.Win.C1Chart.CompassEnum.East;
    this.c1Chart1.Header.Location = new Point(-1, -1);
    this.c1Chart1.Header.Visible = true;
    

    Displaying the Legend

    The following example will position your chart legend to the left and you cana djust the point coordinates to fine tune the position.

    Note: Remember the -1 just uses the default coordinate for the Compass setting, and one or both coordinates can have absolute positions. Just make sure that the point makes sense for the position. For example you probably do not want to set a very high y value for something that has Compass set to North, because the Chart will shrink to accommodate the header.

    To write code in Visual Basic

    Visual Basic
    Copy Code
    c1Chart1.Legend.Text = "My Chart Legend"
    c1Chart1.Legend.Compass = C1.Win.C1Chart.CompassEnum.West
    c1Chart1.Legend.Location = new Point(-1, -1)
    c1Chart1.Legend.Visible = True
    

    To write code in C#

    C#
    Copy Code
    this.c1Chart1.Legend.Text = "My Chart Legend";
    this.c1Chart1.Legend.Compass = C1.Win.C1Chart.CompassEnum.West;
    this.c1Chart1.Legend.Location = new Point(-1, -1);
    this.c1Chart1.Legend.Visible = true;
    
    See Also