C#Dundas图表自动缩放Y轴没有超过100%的值
问题描述:
我在Visual Studio中使用C#使用Dundas图表。C#Dundas图表自动缩放Y轴没有超过100%的值
我的图表显示百分比值,如果我不使用最大y轴值,图表会自动缩放轴 - 但是,有时它会显示超过100%的值(即使没有一个值实际超过100% )。
如何允许轴根据图表值更改大小,但绝不允许它超过100%?
答
对于任何感兴趣的人,我决定以编程方式为每个图表设置Y轴的最大值。
下面的代码被用来从给定的阵列获得的最大值,并返回100或最大值向上舍入为10的倍数:
int GetYAxisMaxValue(decimal[] yValues)
{
var max = yValues.Max();
var output = 0m;
if (yValues.Max() % 10 == 0) output = max;
else output = max + (10 - max % 10);
if (output > 100) return 100;
else return Convert.ToInt32(output);
}
这然后被用于创建该图表,设置:
chart.ChartAreas["Default"].AxisY.Maximum = GetYAxisMaxValue(...);
希望这会有所帮助。
[This](https://stackoverflow.com/questions/45086995/winforms-chart-set-minimum-y-axis-display-range/45091054#45091054)可能会有所帮助。 – TaW