Back to Devexpress

ConstantLine.ShowInLegend Property

corelibraries-devexpress-dot-xtracharts-dot-constantline-33fe84bc.md

latest9.0 KB
Original Source

ConstantLine.ShowInLegend Property

Gets or sets a value that specifies whether the constant line is represented in the chart control’s legend.

Namespace : DevExpress.XtraCharts

Assembly : DevExpress.XtraCharts.v25.2.dll

NuGet Package : DevExpress.Charts

Declaration

csharp
[XtraChartsLocalizableCategory(XtraChartsCategory.Behavior)]
public bool ShowInLegend { get; set; }
vb
<XtraChartsLocalizableCategory(XtraChartsCategory.Behavior)>
Public Property ShowInLegend As Boolean

Property Value

TypeDescription
Boolean

true to represent the constant line in the legend; otherwise, false.

|

Remarks

Use the ShowInLegend property to control whether the constant line is indicated within the chart control’s legend.

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.

csharp
// 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;
vb
' Cast the chart's diagram to the XYDiagram type, to access its axes.
Dim diagram As XYDiagram = CType(chartControl1.Diagram, XYDiagram)

' Create a constant line.
Dim constantLine1 As 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

The following code snippets (auto-collected from DevExpress Examples) contain references to the ShowInLegend property.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

dashboard-constant-lines/CS/ConstantLineExtension.Win/ConstantLineModule.cs#L76

csharp
line.Visible = true;
line.ShowInLegend = false;
line.Color = customConstantLine.Color;

winforms-dashboard-custom-properties/CS/WinForms-Dashboard-Custom-Properties/Modules/ConstantLineUserValueModule.cs#L95

csharp
chartAxis.ConstantLines.Add(line);
line.ShowInLegend = false;
line.Color = Color.Green;

asp-net-web-forms-dashboard-custom-properties-sample/CS/WebFormsDashboardCustomPropertiesSample/Export/ChartConstantLinesExtension.cs#L40

csharp
line.Visible = true;
line.ShowInLegend = false;
line.Color = ColorTranslator.FromHtml(customConstantLine.color);

asp-net-mvc-dashboard-custom-properties-sample/CS/AspMvcDashboardCustomPropertiesSample/Export/ChartConstantLinesExtension.cs#L40

csharp
line.Visible = true;
line.ShowInLegend = false;
line.Color = ColorTranslator.FromHtml(customConstantLine.color);

wpf-dashboard-custom-properties/CS/Wpf-Dashboard-Custom-Properties/Modules/ChartItemModule/ChartOptions/ConstantLine.cs#L93

csharp
chartAxis.ConstantLines.Add(line);
line.ShowInLegend = false;
line.Color = System.Drawing.Color.Green;

winforms-dashboard-custom-properties/VB/WinForms-Dashboard-Custom-Properties/Modules/ConstantLineUserValueModule.vb#L101

vb
chartAxis.ConstantLines.Add(line)
line.ShowInLegend = False
line.Color = Color.Green

asp-net-web-forms-dashboard-custom-properties-sample/VB/WebFormsDashboardCustomPropertiesSample/Export/ChartConstantLinesExtension.vb#L38

vb
line.Visible = True
line.ShowInLegend = False
line.Color = ColorTranslator.FromHtml(customConstantLine.color)

winforms-chart-create-and-customize-a-constant-line/VB/ConstLines/Form1.vb#L39

vb
constantLine1.Visible = True
constantLine1.ShowInLegend = True
constantLine1.LegendText = "Some Threshold"

wpf-dashboard-custom-properties/VB/Wpf-Dashboard-Custom-Properties/Modules/ChartItemModule/ChartOptions/ConstantLine.vb#L117

vb
chartAxis.ConstantLines.Add(line)
line.ShowInLegend = False
line.Color = System.Drawing.Color.Green

See Also

LegendText

Constant Lines

Legends

ConstantLine Class

ConstantLine Members

DevExpress.XtraCharts Namespace