c# - 更新图表中的 y 轴最大值

标签 c# .net winforms charts

我的英语不太好,所以我提前道歉。
我在 WindowsFormsApplication 中尝试使用对象 Chart 进行一些操作。
我构建了一个如下所示的程序: enter image description here
这就是代码:

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);
    }

当我单击第一个按钮 (button1) 时,图表将按我想要的方式显示: button1
但如果之后我点击第二个按钮 (button2),则 y 轴上的点会转义: button2
y 轴的最大值 (250) 保持不变,而是变大。
如何修复我的程序以使图形不会超出该区域?
谢谢,再次抱歉我的英语

最佳答案

您可以调用ResetAutoValues图表方法:

chart1.ResetAutoValues();

关于c# - 更新图表中的 y 轴最大值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32854589/

相关文章:

c# - 为什么 ListView 对某些字符的渲染速度如此之慢?

c# - C# 中的复选框

c# - System.Diagnostics.Debugger.Debug() 停止工作

c# - 我什么时候真正需要使用抽象方法?

c# - 寻找一个简单的C#数字编辑控件

c# - 对象到对象映射实用程序

c# - 字符串缓存。内存优化和重用

.net - 加速跨AppDomain通信

asp.net - 如何在frm(winForms)中创建PasswordHash asp身份o生成PasswordHash

c# - 在 C# (Visual Studio) 中折叠所有 #regions only(!)