Get the touch position in .NET MAUI Cartesian Chart

10 Jul 20262 minutes to read

ChartInteractiveBehavior provides the following override methods to get the x and y positions when touching the SfCartesianChart.

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.

  • OnTouchUp - Called when a user lifts their finger or releases their touch input from the Chart area.
  • OnTouchMove - Called when a user’s finger or touch input device is in contact with the Chart area and moves across its surface.
  • OnTouchDown - Called when the user makes the initial contact of a user’s finger or touch input device with the Chart Area.
<chart:SfCartesianChart>
    <!-- code omitted for brevity -->

    <chart:SfCartesianChart.InteractiveBehavior>
        <local:ChartInteractiveExt/>
    </chart:SfCartesianChart.InteractiveBehavior>

</chart:SfCartesianChart>
SfCartesianChart chart = new SfCartesianChart();
//code omitted for brevity
    
ChartInteractiveExt interactiveExt = new ChartInteractiveExt();
chart.Behaviors.Add(interactiveExt);

this.Content = chart;
public class ChartInteractiveExt: ChartInteractiveBehavior
{
    protected override void OnTouchDown(ChartBase chart, float pointX, float pointY)
    {
        base.OnTouchDown(chart, pointX, pointY);
    }

    protected override void OnTouchMove(ChartBase chart, float pointX, float pointY)
    {
        base.OnTouchMove(chart, pointX, pointY);
    }

    protected override void OnTouchUp(ChartBase chart, float pointX, float pointY)
    {
        base.OnTouchUp(chart, pointX, pointY);
    }
}