Pre loader

Display data values on mouse move

Welcome to the SciChart Forums!

  • Please read our Question Asking Guidelines for how to format a good question
  • Some reputation is required to post answers. Get up-voted to avoid the spam filter!
  • We welcome community answers and upvotes. Every Q&A improves SciChart for everyone

WPF Forums | JavaScript Forums | Android Forums | iOS Forums

0
0

I am trying to display data values on mouse move as displayed by green rectangle in attached image. Values displayed are not correct. I use following logic to calculate point values on mouse move.

internal void UpdateCoordinates(System.Windows.Point point)
{
double xD = xAxis.MajorDelta;
int xDecimals = 1;
if (xD < 1)
{
xDecimals = (int)Math.Round(Math.Abs(Math.Log10(xD))) + 1;
}

        double x = Math.Round(xAxis.GetCurrentCoordinateCalculator().GetDataValue(point.X), xDecimals);

        double yD = yAxis.MajorDelta;
        int yDecimals = 1;
        if (yD &lt; 1)
        {
            yDecimals = (int)Math.Round(Math.Abs(Math.Log10(yD))) + 1;
        }

        double y = Math.Round(yAxis.GetCurrentCoordinateCalculator().GetDataValue(point.Y), yDecimals);

        coordinates.Visibility = System.Windows.Visibility.Visible;
        coordinates.Content = string.Format(&quot;({0},{1})&quot;, x, y);
    }
Images
  • You must to post comments
0
0

Hi Manish,

Which element’s mousemove event are you subscribing to? If you subscribed to SciChartSurface.MouseMove then please note the Mouse point will be relative to the SciChartSurface control (which includes the left YAxis), not relative to the chart pane.

To get the correct output you will have to transform the mouse point using the following code:

// Transforms a mouse point from the RootGrid (which hosts the ScichartSurface) 
// relative to the ModifierSurface (which is overlaid on the chart area only)
var transformedPoint = sciChartSurface.RootGrid.TranslatePoint(inputPoint, sciChartSurface.ModifierSurface);

Now that the mouse point is relative to the ModifierSurface (which covers the chart viewport area) the hit-test will work.

You can see another example of this transformation in the following example:
http://http://www.scichart.com/Abt.Controls.SciChart.SL.ExampleTestPage.html#/Abt.Controls.SciChart.Example;component/Examples/IWantTo/InspectDatapoints/HitTestDatapoints.xaml

// Taken from example IWantTo/InspectDataPoints/HitTestDataPoints
private void SciChartSurfaceMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
   // Perform the hit test relative to the GridLinesPanel
   Point mousePoint = e.GetPosition(sciChartSurface.GridLinesPanel as UIElement);
}

Finally, it sounds to me like you are trying to replicate the behaviour of the RolloverModifier? Have you considered using this modifier instead in your code?

If you need some custom actions then creating a ChartModifier (that inherits or replaces RolloverModifier) might be the best way to go.

Feel free to post if you need further assistance.

Best regards,
Andrew

  • manishdoshi
    I am using OnModifierMouseMove on custom modifier that I have defined to get mouse move public override void OnModifierMouseMove(ModifierMouseArgs e)
  • Andrew Burnett-Thompson
    Then this code which we use in the modifiers should work: public override void OnModifierMouseMove(ModifierMouseArgs e) { // Transforms a mouse point from the RootGrid (which hosts the ScichartSurface) // relative to the ModifierSurface (which is overlaid on the chart area only) var transformedPoint = RootGrid.TranslatePoint(e.MousePoint, ParentSurface.ModifierSurface); }
  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.

Try SciChart Today

Start a trial and discover why we are the choice
of demanding developers worldwide

Start TrialCase Studies