Pre loader

Getting the X Axis Value on Clicking anywhere on chart by using custom hit test modifier

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

Hello,

I just want to get the x-axis value anywhere i click on the chart . Suppose if i click on a chart in centre, i want to get the values of this point(x-axis,y-axis). I am using the custom modifier for hit-testing to check if i click on x-axis,y-axis or on chart. Tell me what should i change in this modifier code to achieve my expected output.

Below is my Custom Modifier Code.

public class HitTestingModifier : ChartModifierBase
{
public override void OnModifierMouseDown(ModifierMouseArgs e)
{
IAxis xAxis = null;
IAxis yAxis = null;
bool isOnYAxis = false;
bool isOnXAxis = false;
bool isOnChart = IsPointWithinBounds(e.MousePoint, ModifierSurface);

        foreach (var axis in YAxes)
        {
            isOnYAxis = IsPointWithinBounds(e.MousePoint, axis);
            if (isOnYAxis)
            {
                yAxis = axis;
                break;
            }
        }

        foreach (var xaxis in XAxes)
        {
            isOnXAxis = IsPointWithinBounds(e.MousePoint, xaxis);
            if (isOnXAxis)
            {
                xAxis = xaxis;
                break;
            }
        }

        if (isOnXAxis)
        {
            MessageBox.Show("X-Axis: " + xAxis.AxisTitle);
        }

        if (isOnYAxis)
        {
            MessageBox.Show("Y-Axis: " + yAxis.AxisTitle);
        }

        base.OnModifierMouseDown(e);
    }

    public bool IsPointWithinBounds(Point point, IHitTestable element)
    {
        var tPoint = ParentSurface.RootGrid.TranslatePoint(point, element);


        bool withinBounds = (tPoint.X <= (element as FrameworkElement).ActualWidth && tPoint.X >= 0)
                            && (tPoint.Y <= (element as FrameworkElement).ActualHeight && tPoint.Y >= 0);

        return withinBounds;
    }
}
Version
5.1.0.11299
Images
  • You must to post comments
Showing 0 results
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