Category / Section
How to get coordinates of x and y in WPF Chart (SfChart)?
1 min read
You can get the coordinates of x and y axes using the MouseDownClick event in WPF Chart (SfChart). In this example, the Mouse.GetPosition(ChartName) gets the x and y coordinates of the window and then converts the coordinates point to value using the PointToValue function.
XAML
<!--The co-ordinates of x and y were shown on MouseDown Event--> <Syncfusion:SfChart Name="ScatterChart" MouseDown="ScatterChart_MouseDoubleClick" Width="700" Height="500">
C#
private void ScatterChart_MouseDoubleClick(object sender, MouseButtonEventArgs e) { Point position = new Point { X = e.GetPosition(ScatterChart).X - ScatterChart.SeriesClipRect.Left, Y = e.GetPosition(ScatterChart).Y - ScatterChart.SeriesClipRect.Top}; //PointToValue converts window coordinates to chart X,Y coordinates double xValue = this.ScatterChart.PointToValue(this.ScatterChart.PrimaryAxis, position); double yValue = this.ScatterChart.PointToValue(this.ScatterChart.SecondaryAxis, position); MessageBox.Show("X: " + xValue + "\n" + "Y: " + yValue); }