Results 1 to 9 of 9

Thread: [RESOLVED] MSchart Scaling and Moving Multiple Data Points

Threaded View

  1. #1

    Thread Starter
    Hyperactive Member Frabulator's Avatar
    Join Date
    Jan 2015
    Location
    USA
    Posts
    409

    Resolved [RESOLVED] MSchart Scaling and Moving Multiple Data Points

    ---- EDIT 2/10/2015 ----

    I have successfully completed my task of Manipulating, Scaling and relocating multiple values in an MSChart in VB.Net code. I needed to use a formula method, which is typed below in comment 7 (I think), which took me several days of calculating to come up with.

    Everything is done through data binding, fraction scaling, and mathematical equations with loops. I have a mouse down, mouse up, mouse click and mouse move event in order to capture all of these.

    BUT!!! My question still remains the same. Is there an easier way to do this?!? This has been going for almost a week (I think) and still no answers.

    Thanks everyone !!!!





    ---- EDIT 2/8/2015 ----

    Well I have answered one of my own questions, which is the relocation of the data points. I figured out after days of smacking my head that I needed to use the MouseClick event instead of the MouseDown event to grab two data points (Duh). But with that information I was able to loop through the data points and move them based on the difference between the old end point and the new location (by math functions).

    So, only thing left is my last question. Which, like I stated before, I have an equation for, its just working out out. Is it still feasible or is there a better way?


    ---- END EDIT ----


    CURRENTLY ALL ANSWERED

    I have a chart that populates from a collection of data in a DataGridView in which its binded. I have many points which need to be selected with either a loop (select point A and point B) or a transparent box drawing (all points within that range). Once selected they need to do two things, to be able to click on selected points and drag all of them to another position on the Y axis (first set of images) or scale the selected points (shown in second images).

    I have the code complete so I can drag/drop and manipulate the position of one point, so I know that the loop method (selecting the start point and end point) would work for relocating each point in that range. My first problem is I don’t know how to select a multi range and loop through them. I have tried the normal loop methods, but I cannot seem to get it to work at all. I think I am doing it completely wrong so I scrapped my loop code and brought it here.

    First question:
    1. How do I set up a loop for datapoints in a spline/line/fastline graph in MSChart?

    COMPLETE


    My next problem is scaling the selected points like in the second set of images? I thought I could do it with a math equation, something like:

    Code:
                Dim i As Integer
                Dim x As Integer
                Dim scaleRation As Integer = 0.05
    
                Dim NumberOfPoints As Integer
                NumberOfPoints = 1
    
                For i = StartPoint To EndPoint
                    NumberOfPoints = NumberOfPoints + 1
                Next
    
                For x = StartPoint To EndPoint
                    x = x * (scaleRation / NumberOfPoints)
                Next
    Of course that is not working code, but the concept is there. A math function of “x * (1/(however many points))” and then the next would be “x * (2/(however many points))” and so on so that it would scale each loop perspectival.

    Second question:
    2. Can my code (well, more like idea) work, and is there an easier way to do this that I have overlooked?

    COMPLETE






    The code that I am currently using to manipulate individual points on the chart is listed below. I am using a Mousedown, MouseMove and Mouseup combined with HitTest to select one point and move it on the Y axis.



    Code:
    Public Class Form1
    
    
    
    
    
    
        Dim dtG2 As DataTable
    
    
        Dim pointIndex As Integer
        Dim pointIndexstart As Integer
        Dim pointIndexend As Integer
    
    
        Private selectedDataPoint As DataPoint = Nothing
        Private selectedDataPointStart As DataPoint = Nothing
        Private selectedDataPointEnd As DataPoint = Nothing
        Private selectedDataPoints As DataPointCollection = Nothing
    
    
    
    
        Dim htrResult As HitTestResult = Nothing
        Dim htrResult2 As HitTestResult = Nothing
    
    
        '/ <summary>
        '/ Mouse Down Event
        '/ </summary>
        Private Sub Chart3_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Chart3.MouseDown
            ' Call Hit Test Method
    
    
            'checks to see if curser is on
          
    
                    'Go through points setting design elements back to default
    
    
                    If e.Button = MouseButtons.Right Then
    
                        Dim hitResult As HitTestResult = Chart3.HitTest(e.X, e.Y)
    
    
                        ' Initialize currently selected data point
                        selectedDataPoint = Nothing
                        If hitResult.ChartElementType = ChartElementType.DataPoint Then
                            selectedDataPoint = CType(hitResult.Object, DataPoint)
                            pointIndex = Chart3.Series(1).Points.IndexOf(selectedDataPoint)
    
                            ' Show point value as label
                            selectedDataPoint.IsValueShownAsLabel = True
    
                            ' Set cursor shape
                            Chart3.Cursor = Cursors.SizeNS
                        End If
                    End If
    
    
    
    
    
    
    
        End Sub 'Chart1_MouseDown
    
        Private Sub Chart3_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Chart3.MouseMove
            ' Check if data point selected
    
    
                If Not (selectedDataPoint Is Nothing) Then
                    ' Mouse coordinates should not be outside of the chart 
                    Dim coordinate As Integer = e.Y
                    If coordinate < 0 Then
                        coordinate = 0
                    End If
                    If coordinate > Chart3.Size.Height - 1 Then
                        coordinate = Chart3.Size.Height - 1
                    End If
                    ' Calculate new Y value from current cursor position
                    Dim yValue As Double = Chart3.ChartAreas(0).AxisY.PixelPositionToValue(coordinate)
                    yValue = Math.Min(yValue, Chart3.ChartAreas(0).AxisY.Maximum)
                    yValue = Math.Max(yValue, Chart3.ChartAreas(0).AxisY.Minimum)
    
                    ' Update selected point Y value
                    selectedDataPoint.YValues(0) = yValue
                    Try
    
    
                        dtG2.Rows(pointIndex).Item("MD") = yValue
                    Catch ex As Exception
    
                    End Try
                    ' Invalidate chart
                    Chart3.Invalidate()
    
    
    
                Else
                    ' Set different shape of cursor over the data points
                    Dim hitResult As HitTestResult = Chart3.HitTest(e.X, e.Y)
                    If hitResult.ChartElementType = ChartElementType.DataPoint Then
                        Chart3.Cursor = Cursors.Hand
                    Else
                        Chart3.Cursor = Cursors.Default
                    End If
                End If
    
        End Sub
    
        '/ <summary>
        '/ Mouse Up Event
        '/ </summary>
        Private Sub Chart3_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Chart3.MouseUp
            ' Initialize currently selected data point
          
                If Not (selectedDataPoint Is Nothing) Then
                    ' Hide point label
                    selectedDataPoint.IsValueShownAsLabel = False
    
                    ' reset selected object
                    selectedDataPoint = Nothing
    
                    ' Invalidate chart
                    Chart3.Invalidate()
    
                    ' Reset cursor style
                    Chart3.Cursor = Cursors.Default
    
    
            End If
    
    
        End Sub 'Chart1_MouseUp
    Moving selected data points to new location (complete)
    Name:  Untitled-1.jpg
Views: 1961
Size:  14.6 KB



    resizing and scaling selected data points (Complete)
    Name:  set 2.jpg
Views: 1280
Size:  16.3 KB


    Thanks for the help!
    Last edited by Frabulator; Feb 10th, 2015 at 09:29 AM.
    Oops, There it goes. Yep... my brain stopped...
    _________________________________

    Useful Things:

    How to link your VB.Net application to Excel

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width