Constant Lines

  • 4 minutes to read

A constant line is a line marker that extends over the chart and indicates an axis value. The constant line is always perpendicular to its axis.


Add a Constant Line


To add a constant line at design time, expand the Diagram item in the Chart Control's Properties window. Expand the AxisX or AxisY item and click the ellipsis button for the ConstantLines property.


Click the Add button to create a constant line. Use the ConstantLine.AxisValue property to specify the constant line's value.

The table below shows constant lines for X- and Y-axis.

Axis / Constant Line Value



ConstantLine.AxisValue = 0:02:30


ConstantLine.AxisValue = 53

Runtime (Code)

The following code demonstrates how to add constant lines at runtime:

XYDiagram diagram = (XYDiagram)chartControl1.Diagram;

ConstantLine temperatureLine = new ConstantLine("Optimal Temperature: 53°C", 53);

ConstantLine timeLine = new ConstantLine("Time: 00:02:30", "00:02:30");

Use the ConstantLine.Visible property to hide/show a constant line.

temperatureLine.Visible = false;

The Chart Control does not take into account constant lines and strips when it calculates axis ranges. You can extend an axis range as described in the Configure Visual and Whole Ranges help section to include the constant line's value in the range.

Runtime (Ribbon UI)

A user should click the Add Vertical Constant Line and Add Horizontal Constant Line buttons in the Chart's Ribbon or Toolbars to add a constant line.

Show the Title

The Title.Text property specifies a constant line's title. The ConstantLineTitle.ShowBelowLine and ConstantLineTitle.Alignment properties specify the title's position and alignment.

Use the TitleBase.TextColor, TitleBase.EnableAntialiasing, and TitleBase.Font properties to customize the title's appearance.

Set the TitleBase.Visible property to true to display the title.

ConstantLine temperatureLine = new ConstantLine();
temperatureLine.AxisValue = 53;

temperatureLine.Title.Text = "Optimal Temperature: 53°C";
temperatureLine.Title.ShowBelowLine = true;
temperatureLine.Title.Alignment = ConstantLineTitleAlignment.Far;
temperatureLine.Title.TextColor = Color.DarkBlue;
temperatureLine.Title.EnableAntialiasing = DefaultBoolean.True;
temperatureLine.Title.Font = new Font("Tahoma", 9F);
temperatureLine.Title.Visible = true;

XYDiagram diagram = (XYDiagram)chartControl1.Diagram;

Display Options

Use the ConstantLine.ShowBehind property to display a constant line over or behind a series.

Property Value Result
ConstantLine.ShowBehind = false ShowBehind_false.png
ConstantLine.ShowBehind = true ShowBehind_true.png
ConstantLine constantLine = new ConstantLine("Value = 2 millions", 2);
constantLine.ShowBehind = false;

The constant line's title is always shown over series.

Show in the Chart Legend

You can display the constant line's description in the chart legend.

Set the ConstantLine.ShowInLegend property to true and specify the ConstantLine.LegendText property.

ConstantLine temperatureLine = new ConstantLine("Optimal Temperature: 53°C", 53);
temperatureLine.ShowInLegend = true;
temperatureLine.LegendText = "Optimal Temperature";
XYDiagram diagram = (XYDiagram)chartControl1.Diagram;

Appearance Options

Use the ConstantLine.Color, ConstantLine.LineStyle.Thickness, and ConstantLine.LineStyle.DashStyle properties to customize the constant line's appearance.

ConstantLine temperatureLine = new ConstantLine("Optimal Temperature: 53°C", 53);
temperatureLine.Color = Color.DarkRed;
temperatureLine.LineStyle.DashStyle = DashStyle.Dot;
temperatureLine.LineStyle.Thickness = 2;

End-User Capabilities

Enable the following options to allow users delete, move, and rename a constant line.

ConstantLine temperatureLine = new ConstantLine("Optimal Temperature: 53°C", 53);
temperatureLine.RuntimeDeletion = true;
temperatureLine.RuntimeMoving = true;
temperatureLine.RuntimeTitleEditing = true;
See Also