Okay, I'm using this code:
Code: Select all
public partial class Form5 : Form
{
TChart tChart1;
System.Windows.Forms.Panel panel1;
public Timer timer;
public Form5()
{
InitializeComponent();
CreateChart();
InitializeChart();
timer = new Timer(this.TimerRun, null, 0, 300);
}
private void InitializeChart()
{
tChart1.AutoRepaint = false;
tChart1.Series.Add(typeof(FastLine));
}
private void CreateChart()
{
panel1 = new System.Windows.Forms.Panel();
this.Controls.Add(panel1);
tChart1 = new TChart();
tChart1.Dock = DockStyle.Fill;
panel1.Dock = DockStyle.Fill;
panel1.Controls.Add(tChart1);
}
private void TimerRun(object sender)
{
var rnd1 = new Random();
double f1 = rnd1.Next(100000);
this.tChart1.AutoRepaint = false;
//this.tChart1[0].Clear();
for (int i = 0; i < 200; i++)
{
double id = this.tChart1[0].Count + 1;
this.tChart1[0].Add(id, Math.Sin(id / f1));
// Thread.Sleep(2);
}
this.tChart1.AutoRepaint = true;
this.tChart1.Invalidate();
}
}
Of course, if you really do not want the chart to be resized while the thread is running and adding in data, all you have to do is to make sure the chart container (TChart or Panel or whatever) has its DockStyle set to something other than 'Fill'.