我在Visual Studio中使用windows窗体图表,我想编写一个函数,在给定图表区域和轴的情况下,从该图表区域中的点返回最大值或最小值(XValue或Yvalue,取决于轴参数)。我想将AxisName枚举用于第二个参数,但与往常一样,msdn的官方文档不包括我。枚举名称是表示ChartArea类的Axes()属性的索引,还是指向Axis对象的直接链接?我需要在我的类(继承DataVisualisation.Charts)中声明枚举,还是它已经为人所知?请帮我
Public Function getAxisMinimum(ByVal area As AreaEnum, ByVal axe As AxisName) As Double
Dim min As Double = Double.NaN
For Each ser As Series In Series
If ser.ChartArea = ChartAreas(area).Name And ser.Points.Count > 0 Then
For Each p As DataPoint In ser.Points
'compare X or Y values depending on the axe argument to set the min
Next
End If
Next
'If there are no points in any series in the area, it will return NaN
Return min
终端功能
AreaEnum是一个整数枚举,表示每个名称对应的ChartArea()属性的索引。
我不需要关于如何比较点的值或如何返回它们的解决方案,我只需要解释如何使用AxisName枚举
无论如何,我想我解决了它。Visual Studio的自动完成给了我答案,因为它识别了AxisName枚举并在select语句中更正了我。我认为这是有效的:
Public Function getAxisMinimum(ByVal area As AreaEnum, ByVal axe As AxisName) As Double
Dim min As Double = Double.NaN
For Each ser As Series In Series
If ser.ChartArea = ChartAreas(area).Name AndAlso ser.Points.Count > 0 Then
For Each p As DataPoint In ser.Points
Select Case axe
Case AxisName.X
If Double.IsNaN(min) OrElse p.XValue < min Then
min = p.XValue
End If
Case AxisName.Y
For Each Yval As Double In p.YValues
If Double.IsNaN(min) OrElse Yval < min Then
min = Yval
End If
Next
Case Else
' Not an acceptable AxisName
Return Double.NaN
End Select
Next
End If
Next
'If there are no points in any series in the area, it will return NaN
Return min
结束函数