You can use Datatable as the data source of the chart, and then use Timer to call the method to get the temperature.
A simple example:
private Timer Timer;
private DataTable Tems;
private void Form1_Load(object sender, EventArgs e)
{
chart1.Series[0].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
chart1.Series[0].Color = Color.Red;
Tems = new DataTable();
Tems.Columns.Add("Time",typeof(int));
Tems.Columns.Add("temperature",typeof(double));
chart1.Series[0].XValueMember = "Time";
chart1.Series[0].YValueMembers = "temperature";
chart1.DataSource = Tems;
chart1.DataBind();
Timer = new Timer();
Timer.Interval = 5 * 1000;
Timer.Tick += Timer_Tick;
Timer.Start();
}
private void Timer_Tick(object sender, EventArgs e)
{
Tems.Rows.Add(h++, 36.5 + n++);
chart1.DataBind();
}
double n = 1.2;
int h = 1;
private void button1_Click(object sender, EventArgs e)
{
Timer.Stop();
}
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.