Title in Windows Forms Chart

18 Nov 20186 minutes to read

Default title

The Title property is used to set the default title for the chart. The chart does not display title text by default.

The following code example displays the default chart title.

chartControl.Text = "Chart Title";
chartControl.Text = "Chart Title"

Chart Title in Windows Forms Chart

Multiple titles

The Titles collection is used to display multiple chart titles. Create a ChartTitle object for each additional title and add it to the collection.

The following code example configures a custom chart title.

ChartTitle chartTitle = new ChartTitle();
chartTitle.Text = "Custom Chart Title";
chartControl.Titles.Add(chartTitle);
' Creates an additional chart title.
Dim chartTitle As New ChartTitle()
chartTitle.Text = "Custom Chart Title"
' Adds the additional title to the chart.
chartControl.Titles.Add(chartTitle)

Multiple Chart Titles in Windows Forms Chart

Title visibility

The Visible determines whether the chart title is shown or hidden. The default value is true.

The following code example hides the chart title.

chartTitle.Visible = false;
chartTitle.Visible = False

Chart Title Visible in Windows Forms Chart

Title alignment

The Alignment property aligns the title within its docked area. The default value is Center. The supported values are:

  • Near: Aligns the title near the beginning of the docked area.
  • Center: Aligns the title at the center of the docked area.
  • Far: Aligns the title near the end of the docked area.

The following code example aligns the chart title near the beginning of its docked area

chartControl.Title.Alignment = ChartAlignment.Near;
chartControl.Title.Alignment = ChartAlignment.Near

Chart Title Alignment in Windows Forms Chart

Title position

The Position property specifies where the title is placed. By default Top is applied. The supported values are:

  • Top: Positions the title at the top.
  • Bottom: Positions the title at the bottom.
  • Left: Positions the title on the left.
  • Right: Positions the title on the right.
  • Floating: Positions the title at a custom location.

The following code example displays the title on the left side of the chart.
 

 
chartControl.Title.Position = ChartDock.Left;
 
 
chartControl.Title.Position = ChartDock.Left
 

Chart Title Position in Windows Forms Chart

Floating title

Set the Position property to Floating and use the Location property to place a title at a custom location.

The following code example displays the chart title at the location (150, 20).

chartTitle.Position = ChartDock.Floating;
chartTitle.Location = new Point(150, 20);
chartTitle.Position = ChartDock.Floating
chartTitle.Location = New Point(150, 20)

Chart Title Location in Windows Forms Chart

Customizing the title

The following properties customize the appearance and layout of a chart title:

  • Font: Specifies the font family, size, and style of the title text. The default value is Verdana, 14 pt, Regular.
  • ForeColor: Specifies the title text color. The default value is Color.Black.
  • BackColor: Specifies the title background color. The default value is Color.Transparent.
  • Margin: Specifies the margin around the title text. The default value is 4.
  • AutoSize: Specifies whether the title size is calculated automatically based on its text. The default value is true.
  • Size: Specifies the height and width of the title when a custom size is required. When AutoSize is set to true, the title size is calculated automatically based on its text.
  • Orientation: Specifies the orientation of the title. The default value is Horizontal. The supported values are:
    • Horizontal: Displays the title horizontally.
    • Vertical: Displays the title vertically.
  • ShowBorder: Controls whether the title border is displayed. The default value is false.
  • Border: Returns the LineInfo object used to customize the title border. This property is read-only.

The Orientation property is applicable only when the title Position is set to Floating.

The following code example customizes the chart title.

chartControl.Title.ForeColor = Color.Red;
chartControl.Title.BackColor = Color.LightGoldenrodYellow;
chartControl.Title.Margin = 6;
chartControl.Title.AutoSize = false;
chartControl.Title.Orientation = ChartOrientation.Horizontal;

chartControl.Title.ShowBorder = true;
chartControl.Title.Border.ForeColor = Color.DarkBlue;
chartControl.Title.Border.Width = 2;
chartControl.Title.Border.DashStyle = DashStyle.Dash;
chartControl.Title.Font = new System.Drawing.Font("Candara", 12F, System.Drawing.FontStyle.Bold);
chartControl.Title.ForeColor = Color.Red
chartControl.Title.BackColor = Color.LightGoldenrodYellow
chartControl.Title.Margin = 6
chartControl.Title.AutoSize = False
chartControl.Title.Orientation = ChartOrientation.Horizontal

chartControl.Title.ShowBorder = True
chartControl.Title.Border.ForeColor = Color.DarkBlue
chartControl.Title.Border.Width = 2
chartControl.Title.Border.DashStyle = DashStyle.Dash
chartControl.Title.Font = New System.Drawing.Font("Candara", 12.0F, System.Drawing.FontStyle.Bold)

Chart title customization in Windows Forms Chart

See also