Pre loader

Put vertical line at chart where nearest X value exists, when mouse button clicked

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

Answered
0
0

I want to put one vertical line to chart, when mouse left button click inside the chart.
And, I want to put vertical line where nearest plotted X value to mouse cursor location in the chart.
No interpolation.

  • Also, I’m using RubberBandXyZoomModifier ExecuteOn=”MouseLeftButton”
    and

  • ZoomPanModifier ExecuteOn=”MouseRigthButton”

What is the best Modifier to use?
And how can it set like that?

Version
v5.1.1.11473
  • You must to post comments
Best Answer
1
1

To place a vertical line at the mouse point, you need to use a few APIs in SciChart together.

For example:

Putting it all together I’ve created an example at our Github repository.

<s:SciChartSurface x:Name="scs" PreviewMouseDown="Scs_OnMouseDown">
    <s:SciChartSurface.XAxis>
        <s:NumericAxis/>
    </s:SciChartSurface.XAxis>
    <s:SciChartSurface.YAxis>
        <s:NumericAxis AxisAlignment="Left"/>
    </s:SciChartSurface.YAxis>
</s:SciChartSurface>


public partial class HitTestToAddAnnotations : Window
{
    public HitTestToAddAnnotations()
    {
        InitializeComponent();
    }

    private void Scs_OnMouseDown(object sender, MouseButtonEventArgs e)
    {
        // Get mouse point
        var mousePoint = e.GetPosition(scs);

        // Transform point to inner viewport 
        // https://www.scichart.com/questions/question/how-can-i-convert-xyaxis-value-to-chart-surface-coodinate
        // https://www.scichart.com/documentation/v5.x/Axis%20APIs%20-%20Convert%20Pixel%20to%20Data%20Coordinates.html
        mousePoint = scs.RootGrid.TranslatePoint(mousePoint, scs.ModifierSurface);

        // Convert the mousePoint.X to x DataValue using axis
        var xDataValue = scs.XAxis.GetDataValue(mousePoint.X);

        // Create a vertical line annotation at the mouse point 
        scs.Annotations.Add(new VerticalLineAnnotation() { X1 = xDataValue});
    }
}

Best regards,
Andrew

  • 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