Chart cursor consumes up to 100 % CPU

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Natalia
Newbie
Newbie
Posts: 5
Joined: Tue Apr 08, 2003 4:00 am
Location: Santa Clara, CA, USA

Chart cursor consumes up to 100 % CPU

Post by Natalia » Tue Feb 01, 2005 7:03 pm

There is a problem with CPU consumption when a chart cursor is enabled.
OnCursorChange event is fired constantly even though mouse cursor does not move.
To reproduce just Enable cursor and move the mouse on the chart area and then leave it there.
I can send a code to reproduce, but I am not sure how to attach it
Thanks

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 Feb 02, 2005 11:55 am

Hi Natalia,

Are you using the latest TeeChart for .NET build release available at our Customer Download Area.

I haven't been able to reproduce this here.
I can send a code to reproduce, but I am not sure how to attach it


Yes please, send us a project we can run "as-is" to reproduce the problem here at steema.public.attachments available at news://www.steema.net
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

Natalia
Newbie
Newbie
Posts: 5
Joined: Tue Apr 08, 2003 4:00 am
Location: Santa Clara, CA, USA

Post by Natalia » Tue Feb 08, 2005 12:22 am

Hi,

I've posted the message with attachment into the newsgroup you told. The version we use is the latest.

Thanks,
Natalia.

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

Post by Narcís » Tue Feb 08, 2005 9:18 am

Hi Natalia,

I've been able to reproduce the behaviour you report. The problem is the code line above.

Code: Select all

m_cursor.FollowMouse = true;
Setting FollowMouse to true makes the cursor work because it has to follow mouse movements. That's why the CPU usage increases, just setting this property to false will solve this problem.
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

Elric
Newbie
Newbie
Posts: 21
Joined: Fri Nov 15, 2002 12:00 am

Post by Elric » Tue Feb 08, 2005 4:21 pm

Hi Narcis
I have the same problem. But in my application deactivating "FollowMouse" solves the problem with the CPU usage but it makes the CursorTool useless.

I want the current y-value from that x-value, where the mouse currently
is. The only way, i found is using the cursortool and the TChart.MouseMove -Event

Code: Select all

mChartLine = New TeeChart.Styles.Line(TChart1.Chart)

Private Sub TChart1_MouseMove(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TChart1.MouseMove
   Dim i As Int32
   Dim x As Double
    x  = CursorTool1.XValue

   ' XValues: order by time
   For i = 0 To mChartLine.XValues.Count - 1
      If x < mChartLine.XValues.Item(i) Then
         Label1.Text = FormatTrend(mChartLine.YValues(i - 1))
      end if	  
   Next
End Sub
If you have an idea for another way, please tell me.

Greetings
Elric

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

Post by Narcís » Tue Feb 08, 2005 4:47 pm

Hi Elric,
If you have an idea for another way, please tell me.
Yes, you can do it much easier using the CalcYPosValue method in the mouse event you want like:

Code: Select all

label1.Text=Convert.ToString(tChart1.Series[0].CalcYPosValue(e.X));
If you don't need the YValue in a label you can use the MarkTips Tool which is specific for this.
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

Elric
Newbie
Newbie
Posts: 21
Joined: Fri Nov 15, 2002 12:00 am

Post by Elric » Tue Feb 08, 2005 5:17 pm

Hi Narcis
Thank you for answering so quickly.

The TChart-Help says about CalcYPosValue-method:
"Returns the pixel Screen Vertical coordinate of the specified Value."

And my test showes me the this, too. What I want is the Y-Value (that I would see on the axes for the current x-value) in the series,not a pixel coordinate. Please look at my code snippet, that gives me the right value, but has the high CPU usage.

Greetings
Elric

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

Post by Narcís » Tue Feb 08, 2005 5:29 pm

Hi Elric,

Yes, you are right, what you are looking for is:

Code: Select all

if (line1.Clicked(e.X,e.Y)!=-1)
				label1.Text=Convert.ToString(line1.YValues[line1.Clicked(e.X,e.Y)]);
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

Elric
Newbie
Newbie
Posts: 21
Joined: Fri Nov 15, 2002 12:00 am

Post by Elric » Tue Feb 08, 2005 6:08 pm

Hi Narcis
Its me again ;)
Okay, its getting nearer. I get the right value, but only for 1 series and only, when cursor is near the series. The advantage of the cursortool-code is, that I get the value, no matter where the cursor is AND (for me important) I get the values of all series at the same time. (Look at my code snippet: I have up to 10 "For"-loops, series, Labels).

Sorry for my nerve-racking questions and thank you for helping me furthermore

Greetings
Elric

Elric
Newbie
Newbie
Posts: 21
Joined: Fri Nov 15, 2002 12:00 am

Post by Elric » Tue Feb 08, 2005 6:57 pm

Okay, I tried something different and it seems to work.

Code: Select all

Dim ChartAreaWidth As Int32
Dim ChartAreaXInterval As Double
Dim XIntervalPerPixel As Double 
Dim XValue As Double

ChartAreaWidth = (TChart1.Chart.Width - CInt(TChart1.Chart.Panel.MarginLeft + TChart1.Chart.Panel.MarginRight))
ChartAreaXInterval = (TChart1.Axes.Bottom.Maximum - TChart1.Axes.Bottom.Minimum)
XIntervalPerPixel = ChartAreaWidth / ChartAreaXInterval
XValue = (e.X - TChart1.Chart.Panel.MarginLeft) / XIntervalPerPixel + TChart1.Axes.Bottom.Minimum
The XValue I calculated myself has the same value as the CursorTool1.XValue. So I can use my original function without the cursortool.
Please look over it, whether I have something forgot or my workaround works only in special cases.

If you have an idea for a more elegant method than my workaround, please tell me.

Thank you again.

Greetings
Elric

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 Feb 09, 2005 1:46 pm

Hi Elric,

Yes, you can try:

Code: Select all

			tChart1.Header.Text="XValue: " + tChart1.Axes.Left.CalcPosPoint(e.Y).ToString()
				+ " YValue: " + tChart1.Axes.Bottom.CalcPosPoint(e.X).ToString();
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

Elric
Newbie
Newbie
Posts: 21
Joined: Fri Nov 15, 2002 12:00 am

Post by Elric » Wed Feb 09, 2005 4:22 pm

Hi, Narcis

Yes, you`re great :D . The value

Code: Select all

tChart1.Axes.Bottom.CalcPosPoint(e.X)
is exactly the X-Value, what i´m looking for. Now it looks so easy.
Thank you again.
Elric

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 Feb 10, 2005 8:53 am

Hi Elric,

You're welcome!

I'm glad to hear finally we found what you needed.
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

Natalia
Newbie
Newbie
Posts: 5
Joined: Tue Apr 08, 2003 4:00 am
Location: Santa Clara, CA, USA

Post by Natalia » Tue Feb 15, 2005 10:49 pm

Thanks for your reply.

Taking out FollowMouse option definitely helps, but it is not convinient - some our systems have trackball and it is very tricky to drag the cusrsor line.

The real problem is that when you turn cursor on and have FollowMouse true, tChart calls OnCursorChange and MouseMove events even when we DO NOT MOVE THE MOUSE over the chart! Just move the mouse to the chart area and leve it there - you'll still constantly get above events.
This is our main concern.

Thanks,
Natalia.

Elric
Newbie
Newbie
Posts: 21
Joined: Fri Nov 15, 2002 12:00 am

Post by Elric » Wed Feb 16, 2005 9:37 am

Hello Natalie
I have the same problem and I solved it with a workaraound.

Code: Select all

   Dim x_old As Int32
   Dim y_old As Int32

   Private Sub TChart1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TChart1.MouseMove

      If e.X <> x_old Or e.Y <> y_old Then
         Me.CursorTool1.FollowMouse = True
      Else
         Me.CursorTool1.FollowMouse = False
      End If
      x_old = e.X
      y_old = e.Y
   End Sub
Its not elegant, its a temporary solution, but it should work until Steema solves the problem.

Bye
Elric

PS: Sorry, that I had used above your thread for my problem. :oops:

Post Reply