我在asp.net C#中填充了一个图表。我有多个图表,每个图表的范围可以从0到125.
如果我没有设置其中一个的最大值,那么如果我的系列范围最大值为125,则图表最大值将变为140:
因此,我想将Y轴的最大值设置为125,但不是为所有图表静态设置它。这意味着我想使其动态仍然像第二个图表图像,最大设置为125.
请指教谢谢。
答案 0 :(得分:0)
// Maximum value in Series, you may have to change YValues[0] to the appropriate
// index for your type of chart (so that it measures the top of your markers)
double maxValue = chart.Series[0].Points.Max(x => x.YValues[0])
// yAxisMax calculated as max value in series + 10 then rounded up to nearest 10
// but capped at 125 below. You could change this to perhaps
// maxValue * 1.1 to always get a 10 % extra above, anything goes
double yAxisMax = Math.Ceiling((maxValue + 10) / 10) * 10;
if (yAxisMax > 125)
yAxisMax = 125;
chart.ChartAreas[0].AxisY.Minimum = 0;
chart.ChartAreas[0].AxisY.Maximum = yAxisMax;
chart.ChartAreas[0].AxisY.Interval = 5;