How do I force a chart to auto adjust Y Axis Maximum?

前端 未结 4 803
梦谈多话
梦谈多话 2021-01-07 17:52

I have a .NET chart which I am populating at runtime

The chart appears within a report. For each band in my report, I clear all the series and add them back in usin

相关标签:
4条回答
  • 2021-01-07 18:13

    you need to run this sequence:

    AxisY.Maximum = Double.NaN; // sets the Maximum to NaN
    AxisY.Minimum = Double.NaN; // sets the Minimum to NaN
    enter code herechart.ChartAreas[0].RecalculateAxesScale(); // recalculates the Maximum and Minimum values, since they are set to NaN
    
    0 讨论(0)
  • 2021-01-07 18:32

    First, initialize this:

    chart.ChartAreas[0].AxisY.IsStartedFromZero = false;
    

    Whenever data point is added, do this please.

    pinChart.ChartAreas[0].RecalculateAxesScale();
    
    0 讨论(0)
  • 2021-01-07 18:34

    chart.ChartAreas[0].RecalculateAxesScale();

    0 讨论(0)
  • 2021-01-07 18:35

    The docs say the default for the Axis.Maximum property is NaN (not a number), so you should be able to re-enable the automatic scaling functionality by setting it back to that value.

    Something like this...

    chart.ChartAreas[0].AxisY.Maximum = Double.NaN;
    

    UPDATE / CORRECTION

    Anton's answer is correct; you should be using:

    ChartArea.RecalculateAxesScale();
    

    According to the RecalculateAxesScale() docs:

    ... it is sometimes necessary to recalculate chart area properties so that the chart is rendered correctly. For example, if an axis range is changed, the labels for that axis must be recalculated.

    Apparently, it's has been available since .NET 4.0.

    0 讨论(0)
提交回复
热议问题