Pre loader

Tag: Mouse

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

1 vote
20k views

Hi all,

As the title indicates, I am trying to get mouse cursor position (Coordinates) from a SciChartSurface in MVVM manner.

I have lots of data bindings to my chart properties in my View Model in the background. This following snipped is a copy of my XAML code in which I have all the data bindings set:

<sci:SciChartSurface Grid.Row="0" Grid.Column="0"
                         RenderableSeries="{Binding SciChartSeriesViewModels}"     
                         Padding="0,8,0,2"                                         
                         sci:ThemeManager.Theme="BrightSpark"                                       
                         YAxes="{Binding SciChartYAxesCollection,Mode=TwoWay}"                                         
                         AutoRangeOnStartup="True"                                       
                         Annotations="{Binding ChartAnnotations}"                                     
                         Name="ApplicationSciChart"                                       
                         ChartModifier ="{Binding ChartModifierGroup}"
                         BorderBrush="LightSlateGray"
                         BorderThickness="1"
                         Visibility="{Binding ChartVisibility}">

        <sci:SciChartSurface.XAxis>
            <sci:TimeSpanAxis AxisTitle="Time"
                              AutoRange="Once" GrowBy="0.03,0.001"
                              TextFormatting=""/>
        </sci:SciChartSurface.XAxis>

  </sci:SciChartSurface>

As can be seen from the code above, the ChartModifier property is one of the items that has Data binding to an instance of a ModiferGroup I have created in my View-Model in the background. The following code is a method that adds members to that ModiferGroup (called ChartModiferGroup in my View-Model):

 private void CreateChartModifiers()
    {
        var rubberBandXyZoomModifier = new RubberBandXyZoomModifier
        {
            ExecuteOn = SciChart.Charting.ChartModifiers.ExecuteOn.MouseLeftButton,
            RubberBandFill = (SolidColorBrush)(new BrushConverter().ConvertFrom("#33FFFFFF")),
            RubberBandStroke = Brushes.SteelBlue, 
            RubberBandStrokeDashArray = new DoubleCollection {2.0, 2.0}
        };

        var zoomPanModifier = new ZoomPanModifier
        {
            ExecuteOn = SciChart.Charting.ChartModifiers.ExecuteOn.MouseMiddleButton,
            ClipModeX = SciChart.Charting.ClipMode.None
        };

        var yAxisDragModifier = new YAxisDragModifier
        {
            DragMode = SciChart.Charting.AxisDragModes.Scale
        };

        var xAxisDragModifier = new XAxisDragModifier
        {
            DragMode = SciChart.Charting.AxisDragModes.Pan
        };

        var mouseWheelZoomModifier = new MouseWheelZoomModifier();

        var zoomExtentsModifier = new ZoomExtentsModifier
        {
            ExecuteOn = SciChart.Charting.ChartModifiers.ExecuteOn.MouseDoubleClick
        };

        var cursorModifier = new CursorModifier
        {
            ReceiveHandledEvents = true,
            ShowAxisLabels = false
        };


        var probeline = new VerticalLineAnnotation()
        {
            Stroke = Brushes.LightSlateGray,
            IsEditable = true,
            ShowLabel = true,
            LabelPlacement = LabelPlacement.Axis,
            Visibility = Visibility.Visible,
            IsHidden = false,
            IsEnabled = true,
            X1 = TimeSpan.FromMilliseconds(-100),
            YAxisId = "Triggered",
            StrokeDashArray = new DoubleCollection { 2.0,2.0},
            StrokeThickness = 1
        };

        var verticalSliceModifier = new VerticalSliceModifier
        {
            IsEnabled = true,
            ShowAxisLabels = true,
            Style = probeline.Style
        };
        verticalSliceModifier.VerticalLines.Add(probeline);


        ChartModifierGroup.ChildModifiers.Add(rubberBandXyZoomModifier);
        ChartModifierGroup.ChildModifiers.Add(rubberBandXyZoomModifier);
        ChartModifierGroup.ChildModifiers.Add(zoomPanModifier);
        ChartModifierGroup.ChildModifiers.Add(yAxisDragModifier);
        ChartModifierGroup.ChildModifiers.Add(xAxisDragModifier);
        ChartModifierGroup.ChildModifiers.Add(mouseWheelZoomModifier);
        ChartModifierGroup.ChildModifiers.Add(zoomExtentsModifier);
        ChartModifierGroup.ChildModifiers.Add(verticalSliceModifier);
        ChartModifierGroup.ChildModifiers.Add(cursorModifier);
    }

What I am trying to do next, is to add functionality in my application, such that I can add more VerticalSliceModifiers to my ChartModifierGroup when a button is pressed. In order to do that, I will require having access to the Mouse cursor position of my SciChartSurface to set the X1 property of the VerticalLineAnnotation, that would be used for the VerticalSliceModifiers (to be created).

In simple words, every time I press a button, I need the position of the mouse pointer to get captured and used as the location of the new VerticalSliceModifer that I am going to create.

I have already read many of the examples and documentation of Sci-Chart such as: Vertical Slice Tooltips Example. However, in this example, the mouse pointer location is accessed is under the xaml.cs and not inside an actual View-Model.

I was wondering if anybody could let me know how I can get access to my SciChartSurface mouse pointer position using true MVVM model.

0 votes
14k views

I have placed a VerticalLineAnnotation on chart surface along with AxisMarkerAnnotation on X-Axis. The X1 of axis marker is bound to the vertical line annotation’s X1 so that they can move together.

I have set IsEditable=”True” and DragDirections=”XDirection” for both – the line annotation & its axis marker so that user can drag the line on chart horizontally by holding the mouse on either the vertical line or its axis marker.

The drag operation works fine when user holds the vertical line with mouse and drags it. The mouse pointer and annotation move together happily.

However, the problem occurs when user holds on the axis marker and tries to drag. In this case, the mouse pointer remains way behind and the annotation moves ahead very fast. There is no sync between mouse pointer position and line annotation which becomes very bad experience for user. Is there any way to address this issue?

  • Anil Soman asked 5 years ago
  • last active 5 years ago
0 votes
9k views

Good afternoon,

I wanted to synchronize the mouse events between graphs, but based on the value of the X axis, not on the position within the graph. In the photo attached below, it is seen that the mouse events are synchronized, and the rollover appears in both graphs. However, what I want is that if, for example, in the graph on the left, the mouse is at time 00: 15: 00.000, in the graph on the right, the rollover also appears at position X 00: 15: 00.000, regardless the width of each graph. Until now I have not been able to get it, as seen when on the left it is at the time 00: 22: 37.00 on the right it appears at the point 00: 10: 23.750.

I would need a way to achieve this with code behind, since I create the graphics programmatically and without MVVM.

As extra information, all charts have the same range of X axis values (they all go from the same start time to the same end time)

Thanks a lot!

0 votes
18k views

Hi

I don’t understand how to disable dragging an annotation with mouse. I didn’t find anything in your documentation.

I have a simple annotation as follows:

                                <s:HorizontalLineAnnotation x:Name="line" IsEditable="False" IsManipulationEnabled="False"  IsAttached="True" Y1="2020" ShowLabel="True" LabelValue="" LabelPlacement="TopRight" Stroke="Red"/>

tried with IsEditable=”False” IsManipulationEnabled=”False” IsAttached=”True” but nothing seems to work.

Could you please help me ?
thank you

  • lorenzo522 asked 8 years ago
  • last active 8 years ago
Showing 4 results

Try SciChart Today

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

Start TrialCase Studies