title: C# - Updating a Chart in Real-Time
body: <p>Bear with me, I'm new to Stack Overflow, but have used it as a resource for a long time when researching methods of programming that I'm not fond with.</p>
  
  <p>I read up a <a href="http://www.dotnetperls.com/chart" rel="nofollow">tutorial on how to create a graph in a C# Windows Forms Application</a>, and was attempting to find out how to make it update itself in real-time if I ever need to use the graph to plot the total amount of data in a sensor. To test it out, I'm using a timer, ticking at every second (1000ms). And before I can use this with a sensor, I'm having two values automatically increment by 1.</p>
  
  <p>The current problem I'm facing is that the chart itself won't update, and only stays the way it was drawn when the form loaded. <a href="http://www.codeproject.com/Questions/558555/RefreshingplusaplusChartplusinplusC" rel="nofollow">I thought it was because I have to redraw the chart with</a> <code>chart1.Update();</code>, and I tried using that before/after recreating the chart every second. However, the result is the same regardless. I just wondered if there's something I haven't done or needs to be changed in order to update the chart in real-time.</p>
  
  <p>This is where the code is at currently:</p>
  
  <pre><code>public partial class Form1 : Form
  {
      int a = 1;
      int b = 2;
  
      public Form1()
      {
          InitializeComponent();
      }
  
      private void Form1_Load(object sender, EventArgs e)
      {
          // Data arrays.
          string[] seriesArray = { "Cats", "Dogs" };
          int[] pointsArray = { a, b };
  
          // Set palette.
          this.chart1.Palette = ChartColorPalette.SeaGreen;
  
          // Set title.
          this.chart1.Titles.Add("Pets");
  
          // Add series.
          for (int i = 0; i &lt; seriesArray.Length; i++)
          {
              // Add series.
              Series series = this.chart1.Series.Add(seriesArray[i]);
  
              // Add point.
              series.Points.Add(pointsArray[i]);
          }
      }
  
      private void timer1_Tick(object sender, EventArgs e)
      {
          a++;
          b++;
  
          // Data arrays.
          string[] seriesArray = { "Cats", "Dogs" };
          int[] pointsArray = { a, b };
  
          // Set palette.
          this.chart1.Palette = ChartColorPalette.SeaGreen;
  
          // Set title.
          this.chart1.Titles.Add("Pets");
  
          // Add series.
          for (int i = 0; i &lt; seriesArray.Length; i++)
          {
              // Add series.
              Series series = this.chart1.Series.Add(seriesArray[i]);
  
              // Add point.
              series.Points.Add(pointsArray[i]);
          }
  
          chart1.Update();
      }
  }
  </code></pre>