Back to Devexpress

ChartHitInfo.ConstantLine Property

wpf-devexpress-dot-xpf-dot-charts-dot-charthitinfo-e271403e.md

latest9.7 KB
Original Source

ChartHitInfo.ConstantLine Property

Gets a constant line which is located under the test point.

Namespace : DevExpress.Xpf.Charts

Assembly : DevExpress.Xpf.Charts.v25.2.dll

NuGet Package : DevExpress.Wpf.Charts

Declaration

csharp
public ConstantLine ConstantLine { get; }
vb
Public ReadOnly Property ConstantLine As ConstantLine

Property Value

TypeDescription
ConstantLine

A ConstantLine object, which represents the constant line located under the test point.

|

Remarks

Use the ConstantLine property to access the constant line located under the test point (if the ChartHitInfo.InConstantLine property returns true ).

And, if ChartHitInfo.InConstantLine is false , the ConstantLine property returns null ( Nothing in Visual Basic).

Example

This example demonstrates how to calculate the hit information for the chart element over which the mouse pointer is hovering.

To accomplish this, handle the ChartControl.MouseMove event, obtain the current chart element via the ChartControl.CalcHitInfo method, and if the element is not null ( Nothing in Visual Basic), display its information.

csharp
using System.Windows;
using System.Windows.Input;
using DevExpress.Xpf.Charts;
using System.Text;

namespace DetermineHoveredChartElement
{

    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void chartControl1_MouseMove(object sender, MouseEventArgs e)
        {
            // Obtain hit information under the test point.
            ChartHitInfo hitInfo = chartControl1.CalcHitInfo(e.GetPosition(chartControl1));
            StringBuilder builder = new StringBuilder();

            // Check whether the chart element is under the test point and if so - obtain the element's content.
            if (hitInfo.InDiagram)
                builder.AppendLine("In diagram");
            if (hitInfo.InAxis)
                builder.AppendLine("In axis:" + hitInfo.Axis.Name);
            if (hitInfo.AxisLabel != null)
                builder.AppendLine("Axis Label:\n" + hitInfo.AxisLabel.Name);
            if (hitInfo.AxisTitle != null)
                builder.AppendLine("Axis title:\n" + hitInfo.AxisTitle.Content);
            if (hitInfo.InTitle)
                builder.AppendLine("In chart title:\n " + hitInfo.Title.Content);
            if (hitInfo.InLegend)
                builder.AppendLine("In legend");
            if (hitInfo.InSeries)
                builder.AppendLine("In series: " + hitInfo.Series.Name);
            if (hitInfo.InSeriesLabel)
            {
                builder.AppendLine("In series label");
                builder.AppendLine("Series Label:" + hitInfo.SeriesLabel.Name);
            }

            if (hitInfo.InSeriesPoint)
            {
                builder.AppendLine("Argument: " + hitInfo.SeriesPoint.Argument);
                builder.AppendLine("Value: " + hitInfo.SeriesPoint.Value);
            }

            // Show hit-testing results 
            if (builder.Length > 0)
                text1.Content = string.Format("Hit-testing results:\n" + builder.ToString());
            else
                text1.Content = "Move the mouse\n pointer over\n the chart to see\n information on\n hovered chart\n elements.";
        }
    }
}
xaml
<Window x:Class="DetermineHoveredChartElement.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525" 
        xmlns:dxc="http://schemas.devexpress.com/winfx/2008/xaml/charts">

    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="130"/>
            <ColumnDefinition />
        </Grid.ColumnDefinitions>
        <StackPanel Grid.Row="0" Grid.Column="0" >
            <Label Name="text1"/>
        </StackPanel>
        <dxc:ChartControl Grid.Row="0" Grid.Column="1" Name="chartControl1"
                          CrosshairEnabled="False" 
                          MouseMove="chartControl1_MouseMove">
            <dxc:XYDiagram2D >
                <dxc:BarSideBySideSeries2D x:Name="series1" LabelsVisibility="True" 
                                            DisplayName="Series1">
                    <dxc:SeriesPoint Argument="A" Value="1" />
                    <dxc:SeriesPoint Argument="B" Value="2" />
                    <dxc:SeriesPoint Argument="C" Value="3" />
                    <dxc:SeriesPoint Argument="D" Value="4" />
                </dxc:BarSideBySideSeries2D>
                <dxc:BarSideBySideSeries2D x:Name="series2" LabelsVisibility="True" 
                                           DisplayName="Series2">
                    <dxc:SeriesPoint Argument="A" Value="4" />
                    <dxc:SeriesPoint Argument="B" Value="3" />
                    <dxc:SeriesPoint Argument="C" Value="2" />
                    <dxc:SeriesPoint Argument="D" Value="1" />
                </dxc:BarSideBySideSeries2D>
                <dxc:XYDiagram2D.AxisY>
                    <dxc:AxisY2D >
                        <dxc:AxisY2D.Title>
                            <dxc:AxisTitle Content="AxisY Title"/>
                        </dxc:AxisY2D.Title>
                        <dxc:AxisY2D.Label>
                            <dxc:AxisLabel Name="AxisYLabel" />
                        </dxc:AxisY2D.Label>
                    </dxc:AxisY2D>
                </dxc:XYDiagram2D.AxisY>
                <dxc:XYDiagram2D.AxisX>
                    <dxc:AxisX2D>
                        <dxc:AxisX2D.Label>
                            <dxc:AxisLabel Name="AxisXLabel"/>
                        </dxc:AxisX2D.Label>
                    </dxc:AxisX2D>
                </dxc:XYDiagram2D.AxisX>
            </dxc:XYDiagram2D>
            <dxc:ChartControl.Titles>
                <dxc:Title Content="My Chart" />
            </dxc:ChartControl.Titles>
            <dxc:ChartControl.Legend>
                <dxc:Legend />
            </dxc:ChartControl.Legend>
        </dxc:ChartControl>
    </Grid>
</Window>
vb
Imports Microsoft.VisualBasic
Imports System.Windows
Imports System.Windows.Input
Imports DevExpress.Xpf.Charts
Imports System.Text

Namespace DetermineHoveredChartElement

    Partial Public Class MainWindow
        Inherits Window
        Public Sub New()
            InitializeComponent()
        End Sub

        Private Sub chartControl1_MouseMove(ByVal sender As Object, ByVal e As MouseEventArgs)
            ' Obtain hit information under the test point.
            Dim hitInfo As ChartHitInfo = chartControl1.CalcHitInfo(e.GetPosition(chartControl1))
            Dim builder As New StringBuilder()

            ' Check whether the chart element is under the test point and if so - obtain the element's content.
            If hitInfo.InDiagram Then
                builder.AppendLine("In diagram")
            End If
            If hitInfo.InAxis Then
                builder.AppendLine("In axis:" & hitInfo.Axis.Name)
            End If
            If hitInfo.AxisLabel IsNot Nothing Then
                builder.AppendLine("Axis Label:" & Constants.vbLf + hitInfo.AxisLabel.Name)
            End If
            If hitInfo.AxisTitle IsNot Nothing Then
                builder.AppendLine("Axis title:" & Constants.vbLf + hitInfo.AxisTitle.Content)
            End If
            If hitInfo.InTitle Then
                builder.AppendLine("In chart title:" & Constants.vbLf & " " & hitInfo.Title.Content)
            End If
            If hitInfo.InLegend Then
                builder.AppendLine("In legend")
            End If
            If hitInfo.InSeries Then
                builder.AppendLine("In series: " & hitInfo.Series.Name)
            End If
            If hitInfo.InSeriesLabel Then
                builder.AppendLine("In series label")
                builder.AppendLine("Series Label:" & hitInfo.SeriesLabel.Name)
            End If

            If hitInfo.InSeriesPoint Then
                builder.AppendLine("Argument: " & hitInfo.SeriesPoint.Argument)
                builder.AppendLine("Value: " & hitInfo.SeriesPoint.Value)
            End If

            ' Show hit-testing results 
            If builder.Length > 0 Then
                text1.Content = String.Format("Hit-testing results:" & Constants.vbLf + builder.ToString())
            Else
                text1.Content = "Move the mouse" & Constants.vbLf & " pointer over" & Constants.vbLf & " the chart to see" & Constants.vbLf & " information on" & Constants.vbLf & " hovered chart" & Constants.vbLf & " elements."
            End If
        End Sub
    End Class
End Namespace

See Also

InConstantLine

ChartHitInfo Class

ChartHitInfo Members

DevExpress.Xpf.Charts Namespace