3

I have an MSChart object with a Series (SeriesChartType.Point); Zooming is enabled to allow the users to zoom into a specific region of the data. After the user has zoomed into that region, I'm interested in knowing the set of DataPoints that are still visible.

Is there a way to ascertain which DataPoints are still visible?

Mario S
  • 11,715
  • 24
  • 39
  • 47

1 Answers1

0

Something like the following should work for you. I tested it with a Line ChartType, but should work for any plotting type as long as the data is X,Y (and not 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

Chris Zeh
  • 924
  • 8
  • 23