Page 1 of 1

Mouse X to Series Value

Posted: Tue Nov 01, 2005 10:02 am
by 9083304
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

Posted: Wed Nov 02, 2005 10:16 am
by narcis
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

Doesn't help

Posted: Wed Nov 02, 2005 10:42 am
by 9083304
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

Posted: Wed Nov 02, 2005 1:54 pm
by narcis
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.

x-axis to series value

Posted: Thu Nov 03, 2005 10:25 am
by 9083304
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

Posted: Thu Nov 03, 2005 2:05 pm
by narcis
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

Thanks

Posted: Fri Nov 04, 2005 8:04 am
by 9083304
Thanks Narcis

That should work!