title: C# - Auto Scale Chart Axis
body: <p>The AxisX works well and only shows the last 50 seconds. <strong>My problem</strong> is that the AxisY doesnt scale automatically and when the values change from 0 to 500 for example it shrinks a lot. I also want to show a proper interval.</p>
  
  <pre><code> private void timercharts_Tick(object sender, EventArgs e)
      {
  
          grafico_pos.Add((int)distancia_atual);
          grafico_pos.Add((int)distancia_desejada);
  
  
          chart_pos.Series[0].Points.AddXY(tempo, distancia_atual);
          chart_pos.Series[1].Points.AddXY(tempo, distancia_desejada);
  
  
  
  
          chart_pos.ChartAreas[0].AxisY.Interval = (grafico_pos.Max() - grafico_pos.Min()/5);
  
          chart_pos.ChartAreas[0].AxisY.Minimum = grafico_pos.Min() - 15;
          chart_pos.ChartAreas[0].AxisY.Maximum = grafico_pos.Max() + 15;
  
  
          if (tempo &gt; 50)
          {
              chart_pos.ChartAreas[0].AxisX.Minimum = tempo - 50;
  
  
              grafico_pos.RemoveAt(0);
              grafico_pos.RemoveAt(0);
  
          }
  
          chart_pos.ChartAreas[0].RecalculateAxesScale();
  
  
          tempo++;
  
      }
  </code></pre>
  
  <p>So basically I want to scale the AxisY based on Max and Min of the points in the last 50 seconds. and adjust the interval correctly.</p>
  
  <p><a href="https://i.stack.imgur.com/PjcjJ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/PjcjJ.png" alt="enter image description here"></a></p>