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

可紊 提交于 2019-12-01 02:13:28

chart.ChartAreas[0].RecalculateAxesScale();

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.

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
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!