How to get coordinates of x and y in WPF Chart (SfChart)?
This article explains how to 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 a 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); }
Output:
Conclusion
I hope you enjoyed learning about how to get coordinates of x and y in WPF Chart(SfChart).
You can refer to our WPF Chart’s feature tour page to know about its other groundbreaking feature representations. You can also explore our WPF Chart documentation to understand how to present and manipulate data.
For current customers, you can check out our WPF components from the License and Downloads page. If you are new to Syncfusion®, you can try our 30-day free trial to check out our WPF Chart and other WPF components.
If you have any queries or require clarifications, please let us know in comments below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!