[Expand]General Information
[Expand]WinForms Controls
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Collapse]WPF Controls
  Prerequisites
 [Expand]What's Installed
 [Expand]Common Concepts
 [Expand]MVVM Framework
 [Collapse]Controls and Libraries
   Reporting
  [Expand]Data Grid
  [Expand]Ribbon, Bars and Menu
  [Collapse]Charts Suite
   [Collapse]Chart Control
    [Expand]Getting Started
    [Expand]Fundamentals
    [Expand]Providing Data
    [Collapse]Chart Elements
     [Expand]Diagram
     [Expand]Series
      Panes
     [Collapse]Axes
       Primary and Secondary Axes
       Axis Scale Types
       Whole and Visual Ranges
       Axis Layout and Appearance
       Axis Labels
       Axis Titles
       Constant Lines
       Strips
       Scale Breaks
       Tickmarks, Grid Lines, and Interlacing
      Legends
      Chart Titles
      Annotations
    [Expand]Appearance Customization
    [Expand]End-User Features
    [Expand]Design-Time Features
    [Expand]Examples
    [Expand]Additional Resources
   [Expand]Chart3D Control
  [Expand]Pivot Grid
  [Expand]Scheduler
  [Expand]Spreadsheet
  [Expand]Rich Text Editor
  [Expand]Tree List
  [Expand]Gauge Controls
  [Expand]Map Control
  [Expand]Layout Management
  [Expand]Windows Modern UI
  [Expand]Printing-Exporting
  [Expand]Data Editors
  [Expand]Navigation Controls
  [Expand]Spell Checker
  [Expand]Property Grid
  [Expand]PDF Viewer
  [Expand]TreeMap Control
  [Expand]Gantt Control
  [Expand]Diagram Control
  [Expand]Windows and Utility Controls
   Dialogs, Notifications and Panels
  [Expand]Scheduler (legacy)
 [Expand]Scaffolding Wizard
 [Expand]Localization
  Redistribution and Deployment
  Get More Help
 [Expand]API Reference
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Office File API
[Expand]Reporting
[Expand]Report and Dashboard Server
[Expand]Dashboard
[Expand]eXpressApp Framework
[Expand]CodeRush
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation

Constant Lines

A constant line is a vertical or horizontal straight line that passes through the chart and indicates an x- or y-axis's value. A constant line is perpendicular to the axis to which it belongs. The Chart Control allows you to draw any number of constant lines over or under Series, and change constant line's appearance. Note that you can only add constant lines to the 2D XY Diagram's axes.

This document consists of the following 'How-To' sections:

Expanded Add a Constant Line to an Axis

The following image shows the y-axis's and x-axis's constant lines:

XAML

Use the following notation to create the constant lines from the image above:

Use the following members to add constant lines to a chart:

Member Description
Axis2D.ConstantLinesInFront The collection of constant lines that are drawn over series.
Axis2D.ConstantLinesBehind The collection of constant lines that are drawn under series.
ConstantLine A constant line.
ConstantLine.Value Specifies the value that the constant line identifies.
ConstantLine.Title Gets or sets the constant line's title.
ConstantLineTitle A constant line's title.
TitleBase.Content Specifies the constant line title's content.
Note

  1. Use the ConstantLine.Visible property to specify a constant line's visibility.
  2. The Chart Control automatically calculates axes' ranges based on all Series' and Indicators' data. You can extend the axis's range to plot a constant line through a value that is out of the automatically calculated range. Refer to the Whole and Visual Ranges help document for more information about ranges.

At Runtime

The code below shows how to add a y-axis at runtime:

The MVVM Design Pattern's Use

To generate constant lines from a ViewModel, bind an axis's ConstantLineItemsSource (Axis2D.ConstantLineBehindItemsSource, Axis2D.ConstantLineInFrontItemsSource) to a collection of objects that contain constant line settings. Use the ConstantLineItemTemplate (Axis2D.ConstantLineBehindItemTemplate, Axis2D.ConstantLineInFrontItemTemplate) or ConstantLineItemTemplateSelector (Axis2D.ConstantLineBehindItemTemplateSelector, Axis2D.ConstantLineInFrontItemTemplateSelector) property to specify how to display constant lines.

The example below shows how to create a constant line for a y-secondary axis.

Tip

A complete sample project is available in the DevExpress Code Examples database at http://www.devexpress.com/example=T541777.

Use the following properties to generate constant lines from a ViewModel:

Property Description
Axis2D.ConstantLineBehindItemsSource Gets or sets the objects' collection to generate constant lines that are drawn under series.
Axis2D.ConstantLineInFrontItemsSource Gets or sets the objects' collection to generate constant lines that are drawn over series.
Axis2D.ConstantLineBehindItemTemplate Specifies the System.Windows.DataTemplate that defines how to convert a model object to a constant line that is under series.
Axis2D.ConstantLineInFrontItemTemplate Specifies the System.Windows.DataTemplate that defines how to convert a model object to a constant line that is over series.
Axis2D.ConstantLineBehindItemTemplateSelector Gets or sets the custom logic to select a data template that converts a model object to a constant line that is drawn under series.
Axis2D.ConstantLineInFrontItemTemplateSelector Gets or sets the custom logic to select a data template that converts a model object to a constant line that is drawn over series.

Expanded Show a Constant Line in a Legend

You can display a constant line's marker with the specified text in the chart legend.

Define the ConstantLine.LegendText property to display a constant line in a legend. A chart's legend does not show a constant line if its LegendText property is not specified.

Expanded Customize Constant Line Appearance

Constant Line's Title

You can modify the constant line title's position and appearance as follows:

Use the code below to display the constant line's title as in the previous image.

The code above uses the following classes and properties:

Member Description
ConstantLineTitle A constant line title.
TitleBase.Content The title's content.
TitleBase.ContentTemplate Specifies how to display the title's content.
ConstantLineTitle.Alignment Specifies the title's alignment.
ConstantLineTitle.ShowBelowLine Specifies whether to show the title below the constant line.

Constant Line's Style

You can change the constant line's style (for example, thickness or color).

Use the following markup to modify a constant line's style:

The markup above uses the following members:

Member Description
ConstantLine.LineStyle Stores the constant line's options.
ConstantLine.Brush Gets or sets the brush that is used to paint the constant line.
LineStyle The line style's options.

Expanded See Also

Is this topic helpful?​​​​​​​