Quinn-Curtis Forums
Quinn-Curtis Forums
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Tools for Microsoft .Net
 SPC Control Chart Tools for .Net
 How to catch the point when it was clicked?
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

fanyorn

3 Posts

Posted - 30 Aug 2009 :  12:07:13  Show Profile  Reply with Quote
Hi,
how to get the point's index when I double click the point on the chart,I have searched all of example CS codes about MouseListener,but there seems no means to get this index value.

Thanks.

quinncurtis

1586 Posts

Posted - 30 Aug 2009 :  18:57:15  Show Profile  Reply with Quote
You can use a subclass of the DataToolTip class, much like the ChartZoom class in the previous example

class CustomToolTip : DataToolTip
        {
            public CustomToolTip(ChartView component)
                : base(component)
            {
            }

            public override void OnDoubleClick(EventArgs me)
            {
                MouseEventArgs mouseevent = (MouseEventArgs)me;
                Point2D mousepos = new Point2D();
                mousepos.SetLocation(mouseevent.X, mouseevent.Y);
                base.OnDoubleClick(me);

                ChartPlot selectedPlot = (ChartPlot)GetSelectedPlotObj();
                if (selectedPlot != null)
                {
                    int selectedindex = GetNearestPoint().GetNearestPointIndex();
                    PhysicalCoordinates transform = GetSelectedCoordinateSystem();


                }
            }
        }


Install it in the main part of the program using code similar to:

CustomToolTip tooltip = new CustomToolTip(this);
            tooltip.SetDataToolTipFormat(ChartObj.DATA_TOOLTIP_CUSTOM);
            tooltip.SetEnable(true);
            this.SetCurrentMouseListener(tooltip);


If you are still using a trial version of the software after more than 30 days, you should think about getting a commercial license.
Go to Top of Page

fanyorn

3 Posts

Posted - 01 Sep 2009 :  11:46:53  Show Profile  Reply with Quote
Thank for your reply,it works now,but we found a strange problem:
The event was not invoked when the following codes was added:
this.HScrollBar1.Value = this.HScrollBar1.Maximum - numdatapointsinview;


Could you please give some explanation about it?

By the way,we now just doing some funtion test on this library,and we are sure of considering the purchase if there is no function problem. -:)

Thanks.
Go to Top of Page

quinncurtis

1586 Posts

Posted - 01 Sep 2009 :  13:47:25  Show Profile  Reply with Quote
You found a flaw in adding an external mouse listener the way we described. Once the scroll bar forces a change, or rebuilding of the graph, the mouse listeners are reset, and only the standard ones are reinitialized for the new graph. External ones like the one you added are not. We can describe simple workaround, but we will wait until you actually own the software.
Go to Top of Page

quahys

Malaysia
7 Posts

Posted - 10 Dec 2013 :  04:25:49  Show Profile  Reply with Quote
Would you mind to post a VB.net version for coding that portion? Because I'm not familiar with C#.
I was wondering when I double click at any data point, could I execute some functions and point index can be retrieved as well.
Any example would be appreciated.
Go to Top of Page

quinncurtis

1586 Posts

Posted - 10 Dec 2013 :  10:17:45  Show Profile  Reply with Quote
It would look something like this.

Private Class CustomToolTip
        Inherits DataToolTip

        Public Sub New(ByVal component As ChartView)
            MyBase.New(component)
        End Sub 'New


        Public Overrides Sub OnDoubleClick(ByVal [me] As EventArgs)
            Dim mouseevent As MouseEventArgs = DirectCast([me], MouseEventArgs)
            Dim mousepos As New Point2D()
            mousepos.SetLocation(mouseevent.X, mouseevent.Y)
            MyBase.OnDoubleClick([me])

            Dim selectedPlot As ChartPlot = DirectCast(GetSelectedPlotObj(), ChartPlot)
            If selectedPlot IsNot Nothing Then
                Dim selectedindex As Integer = GetNearestPoint().GetNearestPointIndex()


                Dim transform As PhysicalCoordinates = GetSelectedCoordinateSystem()
            End If
        End Sub

    End Class



You would add the class defintion to the main SPC Chart class. Using the SPCApplication1 example as a starting point, you would add it to the UserChartControl1 class

Create a public instance of it so you can access throughout the UserChartControl1 class.

Public Class UserChartControl1
    Dim startTime As New ChartCalendar()
    ' The time increment between adjacent subgroups
    Dim timeincrementminutes As Integer = 15

    ' Number of samples per sub group
    Dim numsamplespersubgroup As Integer = 5
    Dim tooltip As CustomToolTip
.
.
.


Instantiate it in the InitializeChart method


    Public Sub InitializeChart()
.
.
.
       ' New data
        SimulateData(50, 30, 15)

        tooltip = New CustomToolTip(Me)
        tooltip.SetEnable(True)

        ' Scale the y-axis of the X-Bar chart to display all data and control limits
        Me.AutoScalePrimaryChartYRange()
        ' Scale the y-axis of the Range chart to display all data and control limits
        Me.AutoScaleSecondaryChartYRange()
        ' Rebuild the chart using the current data and settings
        Me.RebuildChartUsingCurrentData()
.
.
.
   End Sub 'InitializeChart


One last thing. Override the PreDraw method for the UserChartControl1 class and call SetCurrentMouseListener there. This is needed because only the standard mouse listeners are retained after each redraw, and custom ones need to be added back in each time the chart is redrawn.

Public Overrides Sub PreDraw(ByVal g2 As Graphics)
        Me.SetCurrentMouseListener(toolTip)
    End Sub

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
Quinn-Curtis Forums © 2000-2018 Quinn-Curtis, Inc. Go To Top Of Page
Powered By: Snitz Forums 2000 Version 3.4.07