Cursortool tied to multiple series

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
Michael
Newbie
Newbie
Posts: 15
Joined: Thu Mar 06, 2003 5:00 am

Cursortool tied to multiple series

Post by Michael » Thu Dec 04, 2003 4:02 pm

Hi,

Hopefully this is the correct place to post this now...

When we last "spoke" I received the following sample to try to tie a cursortool to multiple series:

private void cursorTool1_Change(object sender,
Steema.TeeChart.Tools.CursorChangeEventArgs e)
{
int xValIndex = line1.XValues.IndexOf(Math.Round(e.XValue, 0));
if(xValIndex >= 0)
label1.Text = line1.YValues[xValIndex].ToString();

}

This is nice and very much along the lines of what I was expecting however since the x axis is time, it can't be rounded. I changed it to the following:
Dim i As Integer
Dim x As Integer
grdLgnd.Rows(0).Caption = Date.FromOADate(e.XValue).ToString("HH:mm:ss")
For i = 1 To chrt1.Series.Count
With chrt1.Series(i - 1)
x = .XValues.IndexOf(e.XValue)
If x >= 0 Then
grdLgnd.Rows(i).Caption = .YValues(x).ToString,"#.00")
End If
End With
Next

grdLgnd is a grid I'm using to display the values where the cursor is located.

x is always -1 as a result of the XValues.IndexOf function which doesn't make any sense to me.
e.XValue = 37954.9583244213
or 11/29/2003 22:59:59...
The range of the chart is 11/29/2003 22:00:00 thru 11/29/2003 23:59:59.
Snap is turned on for the cursortool but since it is not tied to a series specifically, it probably has no effect.

I appreciate the help.
Mike

Michael
Newbie
Newbie
Posts: 15
Joined: Thu Mar 06, 2003 5:00 am

Is this support?

Post by Michael » Fri Dec 19, 2003 9:05 pm

This issue has been going on longer than a month. If this is still under discussion or having to go back to R&D I'd like to know. If no one is looking at this issue still, please advise.

Christopher
Site Admin
Site Admin
Posts: 1349
Joined: Thu Jan 01, 1970 12:00 am
Location: Riudellots de la Selva, Catalonia
Contact:

Post by Christopher » Mon Dec 29, 2003 7:04 am

Hi -
This issue has been going on longer than a month. If this is still under discussion or having to go back to R&D I'd like to know. If no one is looking at this issue still, please advise.
Many apologies for the delay. The following seems to work OK here:

Code: Select all

    private void Form1_Load(object sender, System.EventArgs e) {
      tChart1.Aspect.View3D = false;
      line1.FillSampleValues(8000);
      line1.XValues.DateTime = true;
      line2.FillSampleValues(8000);
      line2.XValues.DateTime = true;
      line3.FillSampleValues(8000);
      line3.XValues.DateTime = true;
      line4.FillSampleValues(8000);
      line4.XValues.DateTime = true;
      line5.FillSampleValues(8000);
      line5.XValues.DateTime = true;
      line6.FillSampleValues(8000);
      line6.XValues.DateTime = true;
      cursorTool1.FollowMouse = true;
      cursorTool1.Style = Steema.TeeChart.Tools.CursorToolStyles.Vertical;
      cursorTool1.Pen.Color = Color.Cyan;
      cursorTool1.Pen.Width = 2;
    }

    private void cursorTool1_Change(object sender, Steema.TeeChart.Tools.CursorChangeEventArgs e) {
      DateTime tmp;
      int xValIndex = line1.XValues.IndexOf(Math.Round(e.XValue, 0));
      if(xValIndex >= 0) {
        tmp = DateTime.FromOADate(line1.YValues[xValIndex]);
        label1.Text = tmp.ToLongDateString();
      }
    }
Could you please modify the above to demonstrate the problem you are experiencing?

Many thanks!
Thank you!

Christopher Ireland (Steema crew)
Please be aware of the newsgroup archives:
http://www.teechart.net/support/search.php
http://groups.google.com
http://codenewsfast.com/

Michael
Newbie
Newbie
Posts: 15
Joined: Thu Mar 06, 2003 5:00 am

Post by Michael » Mon Dec 29, 2003 3:06 pm

Hi,

Thanks for the reply. I created a new C# project, cut and pasted the code sample provided and nothing happens to label1. I set a break in cursorTool1_Change in the if statement. It is never executed. I am not a C# programmer so I could have omitted something in the creation of the project. Form1_Load is executing as I am getting 6 series placed on the chart. I did not rename anything from the default.

Please advise.
Thanks
Mike

Christopher
Site Admin
Site Admin
Posts: 1349
Joined: Thu Jan 01, 1970 12:00 am
Location: Riudellots de la Selva, Catalonia
Contact:

Post by Christopher » Mon Dec 29, 2003 3:46 pm

Hi Michael,
Thanks for the reply. I created a new C# project, cut and pasted the code sample provided and nothing happens to label1. I set a break in cursorTool1_Change in the if statement. It is never executed. I am not a C# programmer so I could have omitted something in the creation of the project. Form1_Load is executing as I am getting 6 series placed on the chart. I did not rename anything from the default.
OK. Well, to associate the cursorTool1_Change() method with the cursorTool1 Change event simply click on the cursorTool1 at designtime, click on the thunder bolt in the properties window and enter cursorTool1_Change in the Change event.

Alternatively you should easily be able to recreate the example using a blank VB.NET project, given that all the TeeChart objects, properties, methods and events are identical.
Thank you!

Christopher Ireland (Steema crew)
Please be aware of the newsgroup archives:
http://www.teechart.net/support/search.php
http://groups.google.com
http://codenewsfast.com/

Michael
Newbie
Newbie
Posts: 15
Joined: Thu Mar 06, 2003 5:00 am

Post by Michael » Wed Dec 31, 2003 2:43 pm

Excellent, that was it and it now works but it is not what I'm looking for. What I am trying to get is the assoc. Y values for each series from the position of the cursortool without the cursortool being tied to a series. Every x value should a corresponding (or nearest) value in every series. I can get, as you've shown, the value for X. Now I need to take that X value back to each series and determine, in a very efficient manner to avoid cursortool movement lag, what is each series Y value for that X.

Thanks

Michael
Newbie
Newbie
Posts: 15
Joined: Thu Mar 06, 2003 5:00 am

Post by Michael » Wed Dec 31, 2003 3:58 pm

In an effort further things along I converted the sample to VB, I'm much more at ease there.... Here's my sample code that does not work.

Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
TChart1.Aspect.View3D = False
Line1.FillSampleValues(8000)
Line1.XValues.DateTime = True
Line2.FillSampleValues(8000)
Line2.XValues.DateTime = True
Line3.FillSampleValues(8000)
Line3.XValues.DateTime = True
Line4.FillSampleValues(8000)
Line4.XValues.DateTime = True
Line5.FillSampleValues(8000)
Line5.XValues.DateTime = True
Line6.FillSampleValues(8000)
Line6.XValues.DateTime = True
CursorTool1.FollowMouse = True
CursorTool1.Style = Steema.TeeChart.Tools.CursorToolStyles.Vertical
CursorTool1.Pen.Color = Color.Cyan
CursorTool1.Pen.Width = 2
End Sub

Private Sub CursorTool1_Change(ByVal sender As Object, ByVal e As Steema.TeeChart.Tools.CursorChangeEventArgs) Handles CursorTool1.Change
Dim i As Integer
Dim x As Integer
Label1.Text = Date.FromOADate(e.XValue).ToString("M/dd/yyyy HH:mm:ss")

x = Line1.XValues.IndexOf(e.XValue)
If x >= 0 Then
Label2.Text = Line1.YValues(x).ToString("#.00")
Else
Label2.Text = ""
End If

End Sub


x in this case is always -1. e.XValue is a valid date as Label1.Text is correct.

I look forward to getting this fixed.
Thanks
Michael

Christopher
Site Admin
Site Admin
Posts: 1349
Joined: Thu Jan 01, 1970 12:00 am
Location: Riudellots de la Selva, Catalonia
Contact:

Post by Christopher » Fri Jan 02, 2004 3:04 pm

Hi Mike,
In an effort further things along I converted the sample to VB, I'm much more at ease there.... Here's my sample code that does not work.
OK ... how about changing the CursorTool1_Change() event to something like this:

Code: Select all

    Private Sub CursorTool1_Change(ByVal sender As Object, ByVal e As Steema.TeeChart.Tools.CursorChangeEventArgs) Handles CursorTool1.Change
        Dim i As Integer
        Dim x As Integer
        Label1.Text = Date.FromOADate(e.XValue).ToString("M/dd/yyyy HH:mm:ss")

        'x = Line1.XValues.IndexOf(e.XValue)
        'If x >= 0 Then
        '    Label2.Text = Line1.YValues(x).ToString("#.00")
        'Else
        '    Label2.Text = ""
        'End If

        Dim tmp As Double
        Dim xValIndex As Integer = Line1.XValues.IndexOf(Math.Round(e.XValue, 0))
        If (xValIndex >= 0) Then
            tmp = Line1.YValues(xValIndex)
            Label2.Text = tmp.ToString("#.00")
        End If
    End Sub
Thank you!

Christopher Ireland (Steema crew)
Please be aware of the newsgroup archives:
http://www.teechart.net/support/search.php
http://groups.google.com
http://codenewsfast.com/

Michael
Newbie
Newbie
Posts: 15
Joined: Thu Mar 06, 2003 5:00 am

Post by Michael » Fri Jan 09, 2004 3:49 pm

Chris,

That works but gets me back to where I was before....

In C, date values can be one very long integer. In VB they are doubles where the integer portion indicates the date, the decimal portion indicates the time of day... like....

?date.FromOADate(e.XValue)
#12/30/2003 11:26:03 PM#
?e.XValue
37985.976434937234

So rounding this value will not work where precision is needed down to the second.

Please advise.
Mike

Christopher
Site Admin
Site Admin
Posts: 1349
Joined: Thu Jan 01, 1970 12:00 am
Location: Riudellots de la Selva, Catalonia
Contact:

Post by Christopher » Tue Jan 13, 2004 3:34 pm

Hi Mike,
So rounding this value will not work where precision is needed down to the second.
Well, the examples we've been using should arrive at that level of precision anyhow, given that FillSampleValues creates data whose XValues increment by one day at a time. However, adding data whose XValues increment by one second does bring this problem to the fore. There seems to be some precision problem with doubles with 9 or 10 decimal places when using ValueList.IndexOf() ... I have added this to the list of defects for the TeeChart for .NET meaning that a fix to it will be considered for inclusion into the next maintenance release. In the meantime I'm afraid I can't suggest a viable workaround which will work with 6 series of 8000 data points each.
Thank you!

Christopher Ireland (Steema crew)
Please be aware of the newsgroup archives:
http://www.teechart.net/support/search.php
http://groups.google.com
http://codenewsfast.com/

Michael
Newbie
Newbie
Posts: 15
Joined: Thu Mar 06, 2003 5:00 am

Post by Michael » Thu Jan 15, 2004 5:53 pm

Chris,

Yes, my sample data has a 4-second periodicity. I may be displaying as many as 12 series over an 8 hour period in 16 separate forms (charts) in one instance of the program. I am doing multiple dynamic chart creation for any time-based data source.

I have enjoyed working with Steema support over the past few years. You all have been able to tackle every problem I've come across and provide an efficient solution. I am looking forward to getting this issue resolved.

I am sorry that this can not be made to work in the current revision level in VB.Net. How can I be informed that this is fixed in a future release? Will you post a response here?

I do miss the direct email for this kind of problem. The forum is great for problem solving where we comsumers have access to every one else's problems and your suggestions,,, 90% of my issues are usually resolved this way. But where a bug is concerned, a direct email when a fix is available would be a very nice improvement. My customers are waiting for this fix also so I need to expedite when a fix is available.

Thanks
Michael

Pep
Site Admin
Site Admin
Posts: 3295
Joined: Fri Nov 14, 2003 5:00 am
Contact:

Post by Pep » Fri Jan 16, 2004 1:51 pm

Hi Michael,

>I be informed that this is fixed in a future release? Will you post a >response here?
No, normally we include a "Release Notes" file in the new releases where you can see which bugfixes/changes has been made.
This file is also available on our web site at :
http://www.steema.com/support/versions.html

>concerned, a direct email when a fix is available would be a very nice >improvement.

There is no current mailing list for version info, but we'll consider for the next releases.

Marc
Site Admin
Site Admin
Posts: 1260
Joined: Thu Oct 16, 2003 4:00 am
Location: Girona
Contact:

Post by Marc » Mon Jan 19, 2004 5:23 pm

Hello Michael,

The posts in this thread have gone some way to getting a Y value from an X Value in a Cursor move event using IndexOf. That works easily on a simple example where integer values can be expected, for exampe on a 0,1,2,3.. indexed X data range.

The technique would prove weak for more 'intricate' numbersets (this uses standard Windows Array.IndexOf) and numbersets where X data could potentially be repeated (giving more than one Y value at an X point).

Assuming only one Y value at any given X value we can offer an alternative approach avoiding indexOf.

eg. Using a bit of rightangle triangle trig

Code: Select all

Private Sub CursorTool1_Change(ByVal sender As Object, ByVal e As Steema.TeeChart.Tools.CursorChangeEventArgs) Handles CursorTool1.Change

    Dim xRange, xSegment, yRange, ySegment, tanTheta As Double
    Dim i, startIdx, endIdx As Integer
    Dim negative As Boolean

    negative = False

    startIdx = 0
    endIdx = Line1.Count - 1

    '******************
    'version release at end of month (Jan 04) will include 
    'the following properties to allow quicker scan though 
    'adjustment will need to be made if data zoomed so that 
    'no points are visible on Chart
    '******************
    'startIdx = Line1.FirstVisibleIndex
    'endIdx = Line1.LastVisibleIndex

    For i = startIdx To endIdx
      If e.XValue > Line1.XValues.Value(i) Then
        If e.XValue < Line1.XValues.Value(i + 1) Then
          xRange = Line1.XValues.Value(i + 1) - Line1.XValues.Value(i)
          yRange = Line1.YValues.Value(i + 1) - Line1.YValues.Value(i)
          If yRange < 0 Then negative = True
          yRange = Math.Abs(yRange)
          xSegment = e.XValue - Line1.XValues.Value(i)
          Exit For
        End If
      End If
    Next i

    tanTheta = xRange / yRange
    ySegment = xSegment / tanTheta

    Label1.Text = e.XValue.ToString()

    If negative = True Then
      Label2.Text = Line1.YValues.Value(i) - ySegment
    Else
      Label2.Text = Line1.YValues.Value(i) + ySegment
    End If
End Sub
There may still be some holes in that code and some ways to make it more efficient but with a check on datetime data here it seems to work ok.

Best regards,
Marc Meumann
Steema Support

Michael
Newbie
Newbie
Posts: 15
Joined: Thu Mar 06, 2003 5:00 am

Post by Michael » Wed Feb 04, 2004 9:43 pm

Marc,

THANK YOU!!!!!!! :D

I'll be awaiting the new release as this is a little sluggish for the larger charts. This week?

Thanks again!!!!
Michael

Pep
Site Admin
Site Admin
Posts: 3295
Joined: Fri Nov 14, 2003 5:00 am
Contact:

Post by Pep » Thu Feb 05, 2004 6:43 pm

Hi Michael,

>This week?
Yes, most likely at the end of this week.

Post Reply