Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/flash/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 图表Y轴在自动缩放和手动范围之间切换_C#_Vb.net_Charts_Visual Studio 2015 - Fatal编程技术网

C# 图表Y轴在自动缩放和手动范围之间切换

C# 图表Y轴在自动缩放和手动范围之间切换,c#,vb.net,charts,visual-studio-2015,C#,Vb.net,Charts,Visual Studio 2015,我想创建一个图表,这样用户可以选择自动缩放y轴,也可以在运行时手动更改轴。我可以自动缩放,直到y轴未使用“向上向下”进行更改,但是,一旦我更改任何“向上向下”,自动缩放将无响应 private void numUD_Graph_Ymax_ValueChanged(object sender, EventArgs e) { try { int newmax = (int)numUD_Graph_Ymax.Value;

我想创建一个图表,这样用户可以选择自动缩放y轴,也可以在运行时手动更改轴。我可以自动缩放,直到y轴未使用“向上向下”进行更改,但是,一旦我更改任何“向上向下”,自动缩放将无响应

 private void numUD_Graph_Ymax_ValueChanged(object sender, EventArgs e)
    {
        try
        {
            int newmax = (int)numUD_Graph_Ymax.Value;
            int allowedmin = (int)numUD_Graph_Ymax.Minimum;
            int allowedmax = (int)numUD_Graph_Ymax.Maximum;

            if (newmax >= allowedmin && newmax <= allowedmax && newmax > chart.ChartAreas[0].AxisY.Minimum)
            {
                chart.ChartAreas[0].AxisY.Maximum = newmax;
                chart.Update();
            }
        }
        catch (Exception exception)
        {
            MessageBox.Show(exception.ToString());
        }
    }

    private void numUD_Graph_Ymin_ValueChanged(object sender, EventArgs e)
    {
        try
        {
            int newmin = (int)numUD_Graph_Ymin.Value;
            int allowedmin = (int)numUD_Graph_Ymin.Minimum;
            int allowedmax = (int)numUD_Graph_Ymin.Maximum;

            if (newmin >= allowedmin && newmin <= allowedmax && newmin < chart.ChartAreas[0].AxisY.Maximum)
            {
                chart.ChartAreas[0].AxisY.Minimum = newmin;
                chart.Update();
            }
        }
        catch (Exception exception)
        {
            MessageBox.Show(exception.ToString());
        }
    }

我哪里做错了?如何在数字升降中自动缩放和加载新坐标,同时还允许用户使用升降进一步修改图形。

在设置了一个
最小值和/或
最大值后,恢复自动缩放的关键是重置(全部)这些价值观:

private void btn_AutoSize_Click(object sender, EventArgs e)
{
    chart.ChartAreas[0].AxisX.Minimum = double.NaN;  /// <-- this is the magic 'number'
    chart.ChartAreas[0].AxisX.Maximum = double.NaN;
    chart.ChartAreas[0].AxisY.Minimum = double.NaN;
    chart.ChartAreas[0].AxisY.Maximum = double.NaN;


 // not quite sure about these lines
 /*  
    chart.ChartAreas[0].RecalculateAxesScale();  
    chart.Update();
    updateUI();

 */

}
如果只想为一个轴启用自动缩放,不确定为什么要为两个轴都设置代码

private void btn_AutoSize_Click(object sender, EventArgs e)
{
    chart.ChartAreas[0].AxisX.Minimum = double.NaN;  /// <-- this is the magic 'number'
    chart.ChartAreas[0].AxisX.Maximum = double.NaN;
    chart.ChartAreas[0].AxisY.Minimum = double.NaN;
    chart.ChartAreas[0].AxisY.Maximum = double.NaN;


 // not quite sure about these lines
 /*  
    chart.ChartAreas[0].RecalculateAxesScale();  
    chart.Update();
    updateUI();

 */

}
private void cbx_AutoRange_CheckedChanged(object sender, EventArgs e)
{
    if (cbx_AutoRange.Checked)
    {
        chart.ChartAreas[0].AxisX.Minimum = double.NaN;
        chart.ChartAreas[0].AxisX.Maximum = double.NaN;
        chart.ChartAreas[0].AxisX.Interval = double.NaN;
        chart.ChartAreas[0].AxisY.Minimum = double.NaN;
        chart.ChartAreas[0].AxisY.Maximum = double.NaN;

        numUD_Graph_Xmin.Enabled = false;
        numUD_Graph_Xmax.Enabled = false;
        numUD_Graph_XInterval.Enabled = false;
        numUD_Graph_Ymin.Enabled = false;
        numUD_Graph_Ymax.Enabled = false;

    }
    else
    {
        numUD_Graph_Xmin.Enabled = true;
        numUD_Graph_Xmin.Value = (decimal)chart1.Series[0].Points.FindMinByValue().XValue;
        numUD_Graph_Xmax.Value = (decimal)chart1.Series[0].Points.FindMaxByValue().XValue;
      //.. etc
      //.. etc

    }

}