Saturday, 24 August 2013

Is there a vay to make this code faster? Drawing a point on chart is slow

Is there a vay to make this code faster? Drawing a point on chart is slow

is there any way to make this work faster?
Here is my sample code in vb.net. This adds a point on a chart at mouse
position but it is quite slow.
Private Sub Chart2_MouseMove(sender As Object, e As MouseEventArgs)
Handles Chart2.MouseMove
Dim coord() As Double = GetAxisValuesFromMouse(e.X, e.Y)
Dim test As Series
Try
Chart2.Series.RemoveAt(1)
Catch ex As Exception
End Try
Dim pt As New DataPoint
pt.XValue = coord(0)
pt.YValues(0) = coord(1)
test = New Series
Chart2.Series.Add(test)
Chart2.Series(test.Name).ChartType = SeriesChartType.Point
Chart2.Series(test.Name).Points.Add(pt)
End Sub
Function returns the coordinates of x and y axis at mouse position.
Private Function GetAxisValuesFromMouse(x As Integer, y As Integer) As
Double()
Dim coord(1) As Double
Dim chartArea = Chart2.ChartAreas(0)
coord(0) = chartArea.AxisX.PixelPositionToValue(x)
coord(1) = chartArea.AxisY.PixelPositionToValue(y)
Return coord
End Function
Result:

No comments:

Post a Comment