我缩放图表,但我遇到了图像中的问题(http://postimage.org/image/74ra418yv/)。这是一个模拟窗口,所以每个 pointpairlist 都是针对每个单位时间计算的。我不会同时显示所有这些。所以我创建了CalculateScale函数来进行缩放。我需要所有列表中的最小 X,Y 和最大 X,Y。我使用CalculateScale 找到x 轴和y 轴的最小值和最大值。它工作得很好,唯一的问题是数字是在一个地区收集的。
public void EditScale(List<PointPairList> lists)
{
GraphScale scale = CalculateScale(lists);
GraphPane.XAxis.Scale.Min = scale.MinX - 20;
GraphPane.XAxis.Scale.Max = scale.MaxX + 20;
GraphPane.YAxis.Scale.Min = scale.MinY - 20;
GraphPane.YAxis.Scale.Max = scale.MaxY + 20;
}
protected GraphScale CalculateScale(List<PointPairList> list)
{
double maximaY = -10000000;
double minimaY = 10000000;
double maximaX = -10000000;
double minimaX = 10000000;
double listMinY, listMaxY, listMinX, listMaxX;
for (int i = 0; i < list.Count; i++)
{
listMaxY = list[i].Max(point => point.Y);
listMinY = list[i].Min(point => point.Y);
if (listMaxY > maximaY)
maximaY = listMaxY;
if (listMinY < minimaY)
minimaY = listMinY;
listMaxX = list[i].Max(point => point.X);
listMinX = list[i].Min(point => point.X);
if (listMaxX > maximaX)
maximaX = listMaxX;
if (listMinX < minimaX)
minimaX = listMinX;
}
return new GraphScale(minimaX, maximaX, minimaY, maximaY);
}