Skip to main content
A newer version of this page is available. .

ConstantLine Class

Represents a constant line within an axis.

Namespace: DevExpress.XtraCharts

Assembly: DevExpress.XtraCharts.v20.2.dll

NuGet Packages: DevExpress.Charts, DevExpress.WindowsDesktop.Charts

Declaration

public class ConstantLine :
    ChartElementNamed,
    IConstantLine,
    IAxisValueContainer,
    IHitTest,
    ICheckableLegendItemData,
    ILegendItemData,
    ICheckableLegendItem,
    ILegendItem,
    IScrollBarAnnotation,
    IDragPoint

Remarks

The ConstantLine class contains settings that define the functionality of constant lines within a chart control’s diagram.

Constant line objects associated with a particualr axis are contained within the axis’s Axis2D.ConstantLines collection which is represented by an object of the ConstantLineCollection type. A particular ConstantLine object can be accessed within the collection either using indexer notation (see the ConstantLineCollection.Item property) or by its name using specific methods of the collection (see the ConstantLineCollection.GetConstantLineByName method).

For more information, refer to Constant Lines.

Example

This example demonstrates how a constant line can be created and customized at runtime.

Since constant lines belong to a diagram’s axis, it’s first required to cast your diagram object to the appropriate diagram’s type. After that, it’s possible to access axes and manage their constant lines collection.

// Cast the chart's diagram to the XYDiagram type, to access its axes.
XYDiagram diagram = (XYDiagram)chartControl1.Diagram;

// Create a constant line.
ConstantLine constantLine1 = new ConstantLine("Constant Line 1");
diagram.AxisY.ConstantLines.Add(constantLine1);

// Define its axis value.
constantLine1.AxisValue = 7;

// Customize the behavior of the constant line.
constantLine1.Visible = true;
constantLine1.ShowInLegend = true;
constantLine1.LegendText = "Some Threshold";
constantLine1.ShowBehind = false;

// Customize the constant line's title.
constantLine1.Title.Visible = true;
constantLine1.Title.Text = "Constant Line Title";
constantLine1.Title.TextColor = Color.Red;
constantLine1.Title.Antialiasing = false;
constantLine1.Title.Font = new Font("Tahoma", 14, FontStyle.Bold);
constantLine1.Title.ShowBelowLine = true;
constantLine1.Title.Alignment = ConstantLineTitleAlignment.Far;

// Customize the appearance of the constant line.
constantLine1.Color = Color.Red;
constantLine1.LineStyle.DashStyle = DashStyle.Dash;
constantLine1.LineStyle.Thickness = 2;

Inheritance

See Also