Page 1 of 2
Chart cursor consumes up to 100 % CPU
Posted: Tue Feb 01, 2005 7:03 pm
by 8876938
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
Posted: Wed Feb 02, 2005 11:55 am
by narcis
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
Posted: Tue Feb 08, 2005 12:22 am
by 8876938
Hi,
I've posted the message with attachment into the newsgroup you told. The version we use is the latest.
Thanks,
Natalia.
Posted: Tue Feb 08, 2005 9:18 am
by narcis
Hi Natalia,
I've been able to reproduce the behaviour you report. The problem is the code line above.
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.
Posted: Tue Feb 08, 2005 4:21 pm
by 6929966
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
Posted: Tue Feb 08, 2005 4:47 pm
by narcis
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.
Posted: Tue Feb 08, 2005 5:17 pm
by 6929966
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
Posted: Tue Feb 08, 2005 5:29 pm
by narcis
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)]);
Posted: Tue Feb 08, 2005 6:08 pm
by 6929966
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
Posted: Tue Feb 08, 2005 6:57 pm
by 6929966
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
Posted: Wed Feb 09, 2005 1:46 pm
by narcis
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();
Posted: Wed Feb 09, 2005 4:22 pm
by 6929966
Hi, Narcis
Yes, you`re great
. 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
Posted: Thu Feb 10, 2005 8:53 am
by narcis
Hi Elric,
You're welcome!
I'm glad to hear finally we found what you needed.
Posted: Tue Feb 15, 2005 10:49 pm
by 8876938
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.
Posted: Wed Feb 16, 2005 9:37 am
by 6929966
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.