我有一个带有系列 (SeriesChartType.Point) 的 MSChart 对象; 启用缩放以允许用户缩放到数据的特定区域。 用户缩放到该区域后,我想知道仍然可见的 DataPoints 集合。
是否有方法确定哪些 DataPoints 仍然可见?
以下类似的代码应该适用于您。我使用Line
ChartType
进行了测试,但只要数据是X,Y
(而不是X,Y,Y
),它就可以适用于任何绘图类型。
Dim Xmin As Double = aChart.ChartAreas(0).AxisX.ScaleView.ViewMinimum
Dim Xmax As Double = aChart.ChartAreas(0).AxisX.ScaleView.ViewMaximum
Dim Ymin As Double = aChart.ChartAreas(0).AxisY.ScaleView.ViewMinimum
Dim Ymax As Double = aChart.ChartAreas(0).AxisY.ScaleView.ViewMaximum
Dim VisibleDataPoints As New Series
For Each pt As System.Windows.Forms.DataVisualization.Charting.DataPoint In aChart.Series(0).Points
If pt.XValue >= Xmin And pt.XValue <= Xmax Then
If pt.YValues(0) >= Ymin And pt.YValues(0) <= Ymax Then
VisibleDataPoints.Points.Add(pt)
End If
End If
Next
VisibleDataPoints.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line
VisibleDataPoints.Color = Color.Red
aChart.Series.Add(VisibleDataPoints)
HTH