Transform axis value to pixel value and vice-versa in .NET MAUI Cartesian Chart
10 Jul 20261 minute to read
SfCartesianChart offers two utility methods to transform a pixel into a chart point and vice-versa.
-
ValueToPoint(ChartAxis axis, double value)- Converts the data point value to the screen point. -
PointToValue(ChartAxis axis, double x, double y)- Converts the screen point to the chart value.
NOTE
Prerequisite: Ensure that the required NuGet package is installed, the necessary namespaces are imported, and the SfCartesianChart control is properly configured in your application. For detailed setup and configuration instructions, refer to the Getting Started guide.
if (chart is SfCartesianChart cartesianChart)
{
// Convert screen point to chart point.
var xValue = cartesianChart.PointToValue(cartesianChart.XAxes[0], pointX, pointY);
var yValue = cartesianChart.PointToValue(cartesianChart.YAxes[0], pointX, pointY);
// Convert chart point to screen point.
var xPoint = cartesianChart.ValueToPoint(cartesianChart.XAxes[0], xValue);
var yPoint = cartesianChart.ValueToPoint(cartesianChart.YAxes[0], yValue);
}