SciChart® the market leader in Fast WPF Charts, WPF 3D Charts, and iOS Chart & Android Chart Components

0
0

Hi.

I need to know the position of mouse click in axes coordinates. I’ve created a modifier for this:

public class CustomPointSelectionModifier : SeriesSelectionModifier
{
    public override void OnModifierMouseUp(ModifierMouseArgs e)
    {
        base.OnModifierMouseUp(e);
        var xcalc = ParentSurface.XAxes.First().GetCurrentCoordinateCalculator();
        var ycalc = ParentSurface.YAxes.First().GetCurrentCoordinateCalculator();
        var poistionPoint = Mouse.GetPosition((IInputElement)ParentSurface);

        var point = new Point()
        {
            X = xcalc.GetDataValue(poistionPoint.X),
            Y = ycalc.GetDataValue(poistionPoint.Y),
        };
        ((SciChartMvvmBindingsViewModel)DataContext).OnMouseUp(e, point);
    }
}

And it works well if axes width is zero. Otherwise, it provides values shifted by axes width (or height for Y-axis)
In my example, it should add an arrow annotation in a click point. Instead of this, it adds an arrow with shifted coordinates.

What am I doing wrong?
Thanks

  • You must to post comments
0
0

Hi Alex,

Only thing you’re doing wrong is not finding the related questions on this topic!

They are:

  1. https://www.scichart.com/questions/question/axis-getdatavalue-returns-unexpected-incorrect-value-when-a-chart-title-or-legend-is-present
  2. https://www.scichart.com/questions/question/modifiermouseargs-bug-report

There is also documentation on this topic here:

Axis APIs – Convert Pixel to Data Coordinates

Transforming Pixels to the Inner Viewport
Given a SciChartSurface with Axis on the left, a mouse-coordinate relative to the SciChartSurface must be transformed relative to the viewport (the central area) before the CoordinateCalculator API can be used. To do this, use the following code.

var sciChartSurface = new SciChartSurface();
  sciChartSurface.PreviewMouseDown += (s,e) =>
  {
         // The mouse-point relative to the SciChartSurface
         Point xy = e.GetPosition(sciChartSurface);
         // Translates the mouse point (from root grid coords) to ModifierSurface coords
         Point x1y1 = sciChartSurface.RootGrid.TranslatePoint(xy, sciChartSurface.ModifierSurface);
         // you can now use this coordinate to convert to data values
         double dataValue = sciChartSurface.XAxis.GetCurrentCoordinateCalculator()
                               .GetDataValue(x1y1.X);
   };
  

Let me know if this helps,

Best regards,
Andrew

  • You must to post comments
0
0

It works!! Thank you very much!!

  • You must to post comments
Showing 2 results
Your Answer

Please first to submit.