title: C# Scaling Axes of chart
body: <p>I have a problem with charts in my application. I want to use charts to display histograms of pictures. I want to add a gradient rectangle under chart with colors from black to R/G/B/White, so I draw it as Background Image of each chart. When values on AxisY ar greater then 1k everything is fine, but when those values have less then 4 digits there is a problem <a href="https://i.stack.imgur.com/JUt5h.png" rel="nofollow noreferrer">screen</a>. Anyone know how to prevent extension of AxisX?
  <a href="https://i.stack.imgur.com/jKRH2.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jKRH2.png" alt="enter image description here"></a></p>
  
  <p>Init charts:</p>
  
  <pre><code>    for(int i = 0; i &lt; 3; i++)
          {
              ca = new ChartArea();
              ca.AxisX.Interval = 1D;
              ca.AxisX.IntervalOffsetType = System.Windows.Forms.DataVisualization.Charting.DateTimeIntervalType.Number;
              ca.AxisX.LabelAutoFitStyle = System.Windows.Forms.DataVisualization.Charting.LabelAutoFitStyles.WordWrap;
              ca.AxisX.MajorGrid.Enabled = false;
              ca.AxisY.MajorGrid.LineColor = System.Drawing.Color.DarkGray;
              ca.BackColor = System.Drawing.Color.Transparent;
              ca.BackSecondaryColor = System.Drawing.Color.Transparent;
              ca.BorderWidth = 0;
              ca.Name = "ChartArea" + i.ToString();
              ca.AxisY.LabelAutoFitStyle = LabelAutoFitStyles.DecreaseFont;
              ca.AxisX.Minimum = 0;
              ca.AxisX.Interval = 256;
              ca.AxisY.IntervalAutoMode = IntervalAutoMode.VariableCount;
  
              s = new Series();
              s.BorderWidth = 0;
              s.ChartArea = "ChartArea" + i.ToString();
              s.IsVisibleInLegend = false;
              s.Name = "Series" + i.ToString(); ;
              s.Color = Colors[i];
              s["PointWidth"] = "1";
  
              HistCharts[i] = new Chart();
              HistCharts[i].Anchor = AnchorStyles.Top | AnchorStyles.Right;
              HistCharts[i].BackColor = Color.Transparent;
              HistCharts[i].BackgroundImageLayout = ImageLayout.None;
              HistCharts[i].BorderlineWidth = 0;
              HistCharts[i].ChartAreas.Add(ca);
              HistCharts[i].Location = new System.Drawing.Point(405, (i + 3) * Form.Height / 6 - 28);
              HistCharts[i].Name = "Chart" + i.ToString();
              HistCharts[i].Series.Add(s);
              HistCharts[i].Size = new System.Drawing.Size(297, Form.Height / 6 - 27);
              HistCharts[i].TabIndex = 6;
              HistCharts[i].Text = "chart" + i.ToString();
              HistCharts[i].Visible = false;
              HistCharts[i].SendToBack();
          }
  
          SetChartImage();
          for(int i = 0; i &lt; 3; i++)
              HistCharts[i].BackgroundImage = HistImages[i];
  </code></pre>
  
  <p>Set new series and paint:</p>
  
  <pre><code>        if(Hists == null)
              {
                  HistCharts[0].Visible = false;
                  HistCharts[1].Visible = false;
                  HistCharts[2].Visible = false;
                  UpdateStatTimer(Time);
                  return;
              }
  
              HistCharts[0].BackgroundImage = HistImages[Hists.Length &gt; 1 ? 1 : 0];
  
              if(Hists[0].SequenceEqual(Hists[1]) &amp;&amp; Hists[0].SequenceEqual(Hists[2]))
              {
                  HistCharts[0].Series[0].Color = Color.Black;
                  HistCharts[0].BackgroundImage = HistImages[0];
                  HistCharts[0].Visible = true;
                  HistCharts[1].Visible = false;
                  HistCharts[2].Visible = false;
              }
              else
              {
                  HistCharts[0].Series[0].Color = Color.Red;
                  HistCharts[0].BackgroundImage = HistImages[1];
                  HistCharts[0].Visible = true;
                  HistCharts[1].Visible = true;
                  HistCharts[2].Visible = true;
              }
  
              int Max = 0;
              for(int i = 0; i &lt; 3; i++)
              {
                  HistCharts[i].Series[0].Points.Clear();
                  HistCharts[i].ChartAreas[0].AxisY.Maximum = Double.NaN;
                  for(int j = 0; j &lt; Hists[i].Length; j++)
                      HistCharts[i].Series[0].Points.AddXY(j + 0.5, Hists[i][j]);
                  HistCharts[i].Update();
                  if(HistCharts[i].ChartAreas[0].AxisY.Maximum &gt; Max)
                      Max = (int) HistCharts[i].ChartAreas[0].AxisY.Maximum;
              }
              if(StatisticsItemCheck.Checked == false)
              {
                  for(int i = 0; i &lt; 3; i++)
                      HistCharts[i].ChartAreas[0].AxisY.Maximum = Max;
              }
  </code></pre>
  
  <p>if all Hists are equal Green and Blue histograms are invisible and Red Histogram becomes GrayScale Histogram</p>