Back to Devexpress

ChartHitInfo.SeriesPoint Property

wpf-devexpress-dot-xpf-dot-charts-dot-charthitinfo-687a05f9.md

latest11.1 KB
Original Source

ChartHitInfo.SeriesPoint Property

Gets a series point 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 SeriesPoint SeriesPoint { get; }
vb
Public ReadOnly Property SeriesPoint As SeriesPoint

Property Value

TypeDescription
SeriesPoint

A SeriesPoint object, specifying the series point located under the test point.

|

Remarks

Use the SeriesPoint property to access the series point located under the test point (if the ChartHitInfo.InSeries property returns true ).

And, if ChartHitInfo.InSeries is false , the SeriesPoint 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

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the SeriesPoint 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.

wpf-charts-display-custom-tooltips-over-the-data-point-hovered-by-the-mouse/CS/Window1.xaml.cs#L16

csharp
if (hitInfo != null && hitInfo.SeriesPoint != null) {
    SeriesPoint point = hitInfo.SeriesPoint;

wpf-charts-display-custom-tooltips-over-the-data-point-hovered-by-the-mouse/VB/Window1.xaml.vb#L17

vb
Dim hitInfo As ChartHitInfo = Me.chartControl1.CalcHitInfo(e.GetPosition(Me.chartControl1))
If hitInfo IsNot Nothing AndAlso hitInfo.SeriesPoint IsNot Nothing Then
    Dim point As SeriesPoint = hitInfo.SeriesPoint

See Also

InSeries

ChartHitInfo Class

ChartHitInfo Members

DevExpress.Xpf.Charts Namespace