我在Visual Studio中使用Windows窗体图表,我想编写一个函数,给定图表区域,轴返回最大值或最小值(XValue或Yvalue,具体取决于轴参数) )从该图表区域的点。我想对第二个参数使用AxisName枚举,但是,按照惯例,msdn的官方documentation不会覆盖我。枚举名称是否表示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枚举
答案 0 :(得分:0)
没关系,我想我解决了。 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
结束功能