The chart shows an error when adding lines

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
Elite
Newbie
Newbie
Posts: 8
Joined: Tue Dec 03, 2019 12:00 am

The chart shows an error when adding lines

Post by Elite » Thu Sep 17, 2020 3:01 am

In my program, I need to dynamically add points to the line.
When I click the button, a line is created, and the method is called regularly to add points.
The line will be recreated when the button is clicked again.
The core code is as follows.

First add a line to the chart through the following code:

Code: Select all

private void btn_Click(object sender, EventArgs e)
{
    tChart1.Series.Clear();
    line = new Line(tChart1.Chart)
    {
        Title = "line1",
        VertAxis = VerticalAxis.Both,
        HorizAxis = HorizontalAxis.Both,
        Color = colorBtn.BackColor
    };
}
Then call the following method to add points:

Code: Select all

public void AddPoint(double x, double y)
{
    line.Add(x, y);
}
Occasionally the phenomenon shown in the figure below will appear. How can I prevent this from happening?
Attachments
1.PNG
1.PNG (15.96 KiB) Viewed 358 times

Christopher
Guru
Posts: 1270
Joined: Fri Nov 15, 2002 12:00 am

Re: The chart shows an error when adding lines

Post by Christopher » Thu Sep 17, 2020 7:55 am

Hello,

which version of TeeChart are you using?

I've prepared a TeeChart example using your code and the latest TeeChart version on NuGet which you can download from here:
http://steema.com/files/public/support/ ... esTEST.zip

As you can see, I'm adding in ten points a second using a timer, and the problem you indicate doesn't seem to occur. Does this example work as expected at your end? Could you please modify the example so I can reproduce your problem at my end?
Best Regards,
Christopher Ireland / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Instructions - How to post in this forum

Elite
Newbie
Newbie
Posts: 8
Joined: Tue Dec 03, 2019 12:00 am

Re: The chart shows an error when adding lines

Post by Elite » Fri Sep 18, 2020 3:50 am

Thanks for your answer,I am also using the latest version on NuGet.
In my program, the line is created every time the button is clicked. Like the following code:

Code: Select all

        private void button1_Click(object sender, EventArgs e)
        {
            //if(timer1.Enabled)
            //{
            //    timer1.Enabled = false;
            //    ChangeButtonTitle(true);
            //}
            //else
            //{
            //    timer1.Enabled = true;
            //    ChangeButtonTitle(false);
            //}
            AddSeries();
            timer1.Enabled = true;
        }
Of course the actual code is more complicated.
This situation does not happen every time, but only in a very small number of times.

Christopher
Guru
Posts: 1270
Joined: Fri Nov 15, 2002 12:00 am

Re: The chart shows an error when adding lines

Post by Christopher » Fri Sep 18, 2020 7:54 am

Hello!

A couple of things:
1) there's a new version of TeeChart on NuGet, v.4.2020.9.16 - does the problem still occur with this version?
2) using the project I sent you, I changed the button click code to this:

Code: Select all

        private void button1_Click(object sender, EventArgs e)
        {
            if(timer1.Enabled)
            {
                timer1.Enabled = false;
                ChangeButtonTitle(true);
            }
            else
            {
                timer1.Enabled = true;
                ChangeButtonTitle(false);
                AddSeries();
            }
        }
I then clicked the button 200 times in a row to try and reproduce the problem, but received no error. How many times do you have to click the button before the error occurs using this code?
Best Regards,
Christopher Ireland / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Instructions - How to post in this forum

Post Reply