Mouse X to Series Value

TeeChart for ActiveX, COM and ASP
Post Reply
Rossmc
Newbie
Newbie
Posts: 27
Joined: Wed Jul 28, 2004 4:00 am
Location: South Africa

Mouse X to Series Value

Post by Rossmc » Tue Nov 01, 2005 10:02 am

I realise this is probably easy but I am pressed for time here so any help appreciated.

If I have a chart that has 200 points along the x-axis
It has a series that starts at point 20

Therefore I have an x-axis from 1 to 200 and a series yvalues array from 1 to 80.

Now if I move the mouse (can't use cursor for this!) I need to translate the actual x position to the relative series value at that x-axis point.

Surely there is an easy way to do this?

Thanks
Ross

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Wed Nov 02, 2005 10:16 am

Hi Ross,

Yes, you can implement something like the following code in the MouseMove event.

Code: Select all

Private Sub TChart1_OnMouseMove(ByVal Shift As TeeChart.EShiftState, ByVal X As Long, ByVal Y As Long)
    With TChart1.Header.Text
        .Clear
        .Add CStr(TChart1.Axis.Bottom.CalcPosPoint(X))
    End With
End Sub
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Rossmc
Newbie
Newbie
Posts: 27
Joined: Wed Jul 28, 2004 4:00 am
Location: South Africa

Doesn't help

Post by Rossmc » Wed Nov 02, 2005 10:42 am

Actually that part I can already do, ie. convert the mouse position to the relative x-axis index.

My series starts at point 20 on the x-axis. Therefore if I convert the mouse position to the x-axis index - let's say 40 - I can't use that to get the correct series value ie; .series(0).yvalues.value(xaxis) as there is an offset of 20.

Please let me know if this is not making sense.

Thanks
Ross

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Wed Nov 02, 2005 1:54 pm

Hi Ross,

I don't understand which is your problem. Could you please send us an example we can run "as-is" to reproduce the problem here or a screen-shot so that we can see the problem?

You can post your files at [url]news://www.steema.net/steema.public.attachments[/url] newsgroup.

Thanks in advance.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Rossmc
Newbie
Newbie
Posts: 27
Joined: Wed Jul 28, 2004 4:00 am
Location: South Africa

x-axis to series value

Post by Rossmc » Thu Nov 03, 2005 10:25 am

Hi Narcis

Was having a problem posting but a very simple example will illustrate my point.

Add a Tchart, a Command button and two text boxes to a form then paste the following code:

Private Sub Command1_Click()
With TChart1
.RemoveAllSeries
.AddSeries scLine
.Series(0).FillSampleValues 100
.AddSeries scLine
.Series(1).SetFunction tfMovavg
.Series(1).FunctionType.Period = 20
.Series(1).DataSource = .Series(0)
End With
End Sub

Private Sub TChart1_OnMouseMove(ByVal Shift As TeeChart.EShiftState, ByVal X As Long, ByVal Y As Long)
Dim xActual As Integer
With TChart1
.Header.Text.Clear
xActual = .Axis.Bottom.CalcPosPoint(X)
.Header.Text.Add CStr(xActual)
If .SeriesCount > 1 Then
Text1.Text = .Series(0).YValues.Value(Val(xActual))
Text2.Text = .Series(1).YValues.Value(Val(xActual))
End If
End With
End Sub

Note that Text2.text values are out for the function it doesn't start at the left most point. How do I get it's correct value at the mouse cursor location?

Thanks
Ross

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Thu Nov 03, 2005 2:05 pm

Hi Ross,

You could implement the MouseMove event like this:

Code: Select all

Private Sub TChart1_OnMouseMove(ByVal Shift As TeeChart.EShiftState, ByVal X As Long, ByVal Y As Long)
    Dim xActual As Integer
    With TChart1
        .Header.Text.Clear
        xActual = .Axis.Bottom.CalcPosPoint(X)
        .Header.Text.Add CStr(xActual)
        If .SeriesCount > 1 Then
            Text1.Text = .Series(0).YValues.Value(Val(xActual))
            If xActual >= .Series(1).FunctionType.Period Then
                Text2.Text = .Series(1).YValues.Value(Val(xActual - .Series(1).FunctionType.Period))
            Else
                Text2.Text = ""
            End If
        End If
    End With
End Sub
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Rossmc
Newbie
Newbie
Posts: 27
Joined: Wed Jul 28, 2004 4:00 am
Location: South Africa

Thanks

Post by Rossmc » Fri Nov 04, 2005 8:04 am

Thanks Narcis

That should work!

Post Reply