2

my English is not so good so I apologize in advance.
I tried something with the object Chart in a WindowsFormsApplication.
I built a program that looks like this: enter image description here
And that is the code:

private void Form1_Load(object sender, EventArgs e)
    {
        chart1.Dock = DockStyle.Fill;
        chart1.Series.Clear();
    }

    private void button1_Click(object sender, EventArgs e)
    {
        chart1.Series.Clear();
        chart1.Series.Add("button1 Series");

        for (int i = 1; i <= 100; i++)
            chart1.Series[0].Points.AddXY(i, i * 2);
    }

    private void button2_Click(object sender, EventArgs e)
    {
        chart1.Series.Clear();
        chart1.Series.Add("button2 Series");

        for (int i = 1; i <= 100; i++)
            chart1.Series[0].Points.AddXY(i, i * 4);
    }

When I click the first button (button1), the graph is displayed as I want: button1
But if after that I hit the second button (button2), points on the y-axis escape out:button2
The maximum of the y-axis (250) stay the same instead change to bigger.
How can I fix my program so that the graph will not get out of the area?
Thanks, and sorry again for my English

Roni
  • 73
  • 2
  • 8

2 Answers2

3

You can call ResetAutoValues method of the chart:

chart1.ResetAutoValues();
Reza Aghaei
  • 120,393
  • 18
  • 203
  • 398
0

I used the chart.ChartAreas[0].RecalculateAxesScale() method successfully.

Look at this answer.

Community
  • 1
  • 1
Doc
  • 343
  • 3
  • 13