Roni
Roni

Reputation: 73

Update y-axis maximum in chart

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

Upvotes: 2

Views: 2305

Answers (2)

Reza Aghaei
Reza Aghaei

Reputation: 125197

You can call ResetAutoValues method of the chart:

chart1.ResetAutoValues();

Upvotes: 3

Doc
Doc

Reputation: 358

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

Look at this answer.

Upvotes: 0

Related Questions