Page 1 of 1
Real-Time Charting Problem
Posted: Mon Jul 07, 2008 3:55 am
by 9237602
Dear friends:
Real-time charting with TeeChart .net v3, there is a problem:
There is a fastline "fastline1" in a TeeChart "tchart1", I want to add some data into fastline1 and "tchart1" will repaint at the same time.
I have tried 2 ways:
tchart1.AutoRepaint = true;
1: Use "For(){...}", the codes:
Random rd = new Random();
for (int i = 0; i < 10000; i++)
{
fastLine1.Add(rd.Next(0, 10));
}
Result: tchart1 did not real-time charting as i wish.
I think tchart1 will update 10000 times, because tchart1.AutoRepaint = true, so when a data was added to fastlines1, it will repaint, it means realtime charting. But in fact, it repaint only one time, when the "for " is over.
Why tchart1 did not real time charting? I think may be the time interval between two steps of the "for" is too short, so the tchart1 did not repaint, and i change the codes like this:
for (int i = 0; i < 100000000; i++)
{
if (i%1000000==0)
{
fastLine1.Add(rd.Next(0, 10));
}
}
the time interval is much longer, however, the result is the same as the old: tchart1 did not real-time charting.
2: Use a Timer "timer1" :
timer1.Interval = 1;//1 ms
Random rd = new Random();
private void timer1_Tick(object sender, EventArgs e)
{
fastLine1.Add(rd.Next(0, 10));
}
Result: tchart1 real-time charting.
the questions:
1, I thick adding data in the way of "For(){...}" and Timer are the same in the essentially, they are both add data to fastline one by one. but why the result are so different? How does the "AutoRepaint" property work?
2, The method 2 can real-time charting, but the speed is not very fast. The timer must be added, adn the mini time interval is 1 ms, which is very long for me. In my work, there are two process:A and B, A sends curve data and B receives the data and draw chart dynamicly with TeeChart, the speed is very fast, maybe 10000 times in 1 second, and i want the TeeChart Real-Time Charting as fast as possible. So the question is : Can the TeeChart do this? if "Yes", How can it do?
Please forgive my poor English. ^_^
if you have any idea, please contact me:
e-mail:
xiongxuanwen@163.com
Thank you very much!
Posted: Mon Jul 07, 2008 7:30 am
by narcis
Hi cepri,
For information on how to use AutoRepaint please read the
Real-time Charting article
here. This is a Delphi and TeeChart VCL article but most of it can also be applied to .NET version. It will also help increase your application's performance. I also recommend you to have a look at the
All Features\Welcome !\Speed\Realtime charting examples in the features demo.
Hope this helps!
Posted: Tue Jul 08, 2008 9:35 am
by 9237602
narcis wrote:Hi cepri,
For information on how to use AutoRepaint please read the
Real-time Charting article
here. This is a Delphi and TeeChart VCL article but most of it can also be applied to .NET version. It will also help increase your application's performance. I also recommend you to have a look at the
All Features\Welcome !\Speed\Realtime charting examples in the features demo.
Hope this helps!
Hi Narcís Calvet ,
Thank you for your help!
I have read the article and demo you mentioned, but the problem still exists.
1. Use for loop to add points in .net:
Random rd = new Random();
for (int i = 0; i < 10000; i++)
{
fastLine1.Add(rd.Next(0, 10));
}
The result: the tchart1 does not real-time charting: the fastLine1 does not show in the process of the loop, it shows in the end of the loop.
But in c++ builder, I use loop to add points, the tchart will do real-time charting, it's very strange.
2. Use timer to add points:
timer1.Interval = 1;//1 ms
Random rd = new Random();
private void timer1_Tick(object sender, EventArgs e)
{
fastLine1.Add(rd.Next(0, 10));
}
The result: the tchart1real-time charting: the fastLine1 shows and changes when one data have been added to fastLine1.
The two methods are both to add data to fastLine1 one by one, but why the result is so different?
If I want to do real-time charting, using loop to add points to series, what should I do?
Thank you again!
Posted: Tue Jul 08, 2008 10:34 am
by narcis
Hi cepri,
The problem could be that the chart hasn't had the time to be painted one another point is already added. You can try using code below after calling Add method.
Code: Select all
fastLine1.RefreshSeries();
Thread.Sleep(1000);
Hope this helps!
Posted: Wed Jul 09, 2008 12:56 am
by 9237602
narcis wrote:Hi cepri,
The problem could be that the chart hasn't had the time to be painted one another point is already added. You can try using code below after calling Add method.
Code: Select all
fastLine1.RefreshSeries();
Thread.Sleep(1000);
Hope this helps!
Hi Narcís Calvet,
Thank you!
I have try the method like this:
for (int i = 0; i < 100; i++)
{
fastLine1.Add(rd.Next(0, 10));
fastLine1.RefreshSeries();
Thread.Sleep(1000);
}
but it does not work as I wish, the fastLine1 doesn't show point by point in the process of the loop, it shows as a whole line at the end of the loop.
Do you have any e-mail? I want to send the project to you.
Thanks.
Posted: Wed Jul 09, 2008 7:32 am
by narcis
Hi cepri,
Yes, please, send us a simple example project we can run "as-is" to reproduce the problem here.
You can either post your files at news://
www.steema.net/steema.public.attachments newsgroup or at our
upload page.
Thanks in advance.
Posted: Thu Jul 10, 2008 1:45 am
by 9237602
Hi Narcís Calvet,
I have upload the project files to upload page, the file name is "real-time charting.rar" , please check it.
Hope for your help!
Thanks!
Posted: Thu Jul 10, 2008 8:50 am
by narcis
Hi cepri,
Using the for loop for populating series works fine for me here, series is being refreshed as points are added to it. I'm using latest TeeChart for .NET v3 build available at the client area, which was posted on 2nd July (build 3.5.3105.20150/1/2). Could you please try if this version works better at your end?
Regarding the timer issue, you could try doing something like this:
Code: Select all
private void timer1_Tick(object sender, EventArgs e)
{
//fastLine1.Add(rd.Next(0, 10));
for (int i = 0; i < 10; i++)
{
fastLine1.Add(rd.Next(0, 10));
//tChart1.Refresh();//repaint the chart
}
fastLine1.RefreshSeries();
}
This works fine for me too.
Posted: Tue Jul 15, 2008 7:20 am
by 9237602
Hi,Narcís Calvet
With the new version, it still cann't do real time plotting.
Inorder to check if the chart is plotted all points at the same time or plotted one point after another, I change a few of the code in the file named "FastLine_Realtime.cs" for the demoprojects. Now. the demo of "Fast Delete and Fast pen" chart will plot 10 points. After the button "Start" is pressed, it will delay 10 seconds and then plot all points at once. But what I need is that it will plot one point every 1 second.
The version I used is as below:
Release Notes 3rd July 2008
TeeChart.NET version 3
Build 3.5.3105.20155
The changed code of the file ""FastLine_Realtime.cs"" in demo is:
private void button1_Click(object sender, System.EventArgs e)
{
if (Stopped)
{
// Start loop...
button1.Text="&Stop";
textBox2.Enabled=false;
textBox3.Enabled=false;
MaxPoints=10;
// Prepare variables
// MaxPoints=Convert.ToInt32(textBox2.Text);
ScrollPoints=Convert.ToInt32(textBox3.Text);
tChart1.Axes.Bottom.SetMinMax(1,MaxPoints);
tChart1.Axes.Left.SetMinMax(-30,30);
// Clear
fastLine1.Clear();
fastLine2.Clear();
Random r = new Random();
fastLine1.Add(r.Next(10));
fastLine2.Add(r.Next(10));
Application.DoEvents();
Stopped=false;
// Start loop
while (!Stopped)
{
System.Threading.Thread.Sleep(1000);
// Add one more point
RealTimeAdd(fastLine1);
RealTimeAdd(fastLine2);
fastLine1.RefreshSeries();
if (fastLine1.Count>MaxPoints-1)
break;
}
}
else
{
// Finish
Stopped=true;
button1.Text="&Start";
textBox2.Enabled=true;
textBox3.Enabled=true;
}
}
Posted: Tue Jul 15, 2008 9:21 am
by 13049497
Hi cepri,
i think instead of "fastLine1.RefreshSeries();" you must using "tChart1.Refresh();" or "tChart1.AutoRepaint=true;"?
Posted: Wed Jul 16, 2008 1:48 am
by 9237602
Hi,Narcís Calvet
If I use "tChart1.Refresh()", The chart can do real time charting. But the plot speed is very slow, especially for a large number of XY points.
if I use "tChart1.AutoRepaint=true", "tChart1.Refresh()" must be used for real-time charting.
The property "tChart1.AutoRepaint" in C#.Net does not working in the way as the user manual says, and is different from that in c++ builder.
In c++ builder, If tChart1.AutoRepaint is false, the chart can do real time charting, although the plotting speed is not very satisfactory for a large number of XY points.
Best Regards
CEPRI
Posted: Wed Jul 16, 2008 1:57 am
by 9237602
Hi Narcís Calvet,
Thank you!
If I use "tChart1.Refresh();" , the chart will do real time charting, but the speed is very slow, especially for a large number of XY points.
The property "tChart1.AutoRepaint" in C#.Net does not work in the way as the user manual says, and is different from that in C++ builder.
In C++ builder, if the property "tChart1.AutoRepaint" is false, the function of real time charting is right, although the speed is not very satisfactory for a large number of XY points.
_________________
Best Regards
CEPRI
Posted: Wed Jul 16, 2008 6:37 am
by 13049497
Hi cepri,
i use the following changes to do realtime charting:
Code: Select all
tChart1.BackColor = System.Drawing.Color.Transparent;
tChart1.Header.Visible = false;
tChart1.Legend.Visible = false;
tChart1.Panel.Brush.Gradient.Visible = false;
tChart1.Panning.Allow = Steema.TeeChart.ScrollModes.None;
tChart1.Walls.Visible = false;
tChart1.Zoom.Allow = false;
tChart1.Aspect.View3D = false;
tChart1.Aspect.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.Default;
tChart1.Aspect.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SystemDefault;
tChart1.Aspect.ZoomText = false;
tChart1.Aspect.ClipPoints = false;
tChart1.AutoRepaint = true;
tChart1.Axes.Bottom.Labels.RoundFirstLabel = false;
tChart1.Axes.Left.AxisPen.Width = 1;
tChart1.Axes.Bottom.AxisPen.Width = 1;
tChart1.Axes.Left.Grid.Visible = false;
tChart1.Axes.Bottom.Grid.Visible = false;
tChart1.Axes.Left.Automatic = false;
tChart1.Axes.Left.SetMinMax(-1, 1);
tChart1.Axes.Bottom.Increment = 10;
fastLine1.XValues.Order = Steema.TeeChart.Styles.ValueListOrder.None;
fastLine1.AutoRepaint = false;
fastLine1.DrawAllPoints = false;
fastLine1.LinePen.Width = 1;
I use a timer and his tick method. In my testapplication i draw a sinus with a maximum of 80 visible points, a new point cause an delete of index 0 "fastLine1.Delete(0);". So it is possible for me to draw about 27-35 points per sec. If in that time the chart draw realtime i cant see
i hope it can help you.
Bye