Create an array with chart points

Stéphani Pinheiro Ferreira 1 Reputation point

Hello, I'm creating a graph that records temperature values recorded over time, so that the X axis records the hours and the Y axis records the temperature values.
What I need is to save the temperature values registered in an array or a list, that is, create a list of temperatures.

How do I do this?

An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,409 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Timon Yang-MSFT 9,576 Reputation points

    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();  
                chart1.Series[0].XValueMember = "Time";  
                chart1.Series[0].YValueMembers = "temperature";  
                chart1.DataSource = Tems;  
                Timer = new Timer();  
                Timer.Interval = 5 * 1000;  
                Timer.Tick += Timer_Tick;  
            private void Timer_Tick(object sender, EventArgs e)  
                Tems.Rows.Add(h++, 36.5 + n++);  
            double n = 1.2;  
            int h = 1;  
            private void button1_Click(object sender, EventArgs e)  

    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.

    0 comments No comments