Results 1 to 4 of 4

Thread: Arranging data points

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2011
    Posts
    71

    Arranging data points

    I'm using mscharts, but my question might not need to be chart related to be answered.


    My chart contains 5 XY data points that will be shown in a spline (line graph). The X values are from text boxes 1-5, my Y values are from textboxes 6-10. I'm adding them to my chart by code.

    Code:
    Chart1.Series(0).Points.AddXY(Val(TextBox1.Text), Val(TextBox6.Text))
            Chart1.Series(0).Points.AddXY(Val(TextBox2.Text), Val(TextBox7.Text))
            Chart1.Series(0).Points.InsertXY(Val(TextBox3.Text), Val(TextBox8.Text))
            Chart1.Series(0).Points.AddXY(Val(TextBox4.Text), Val(TextBox9.Text))
            Chart1.Series(0).Points.AddXY(Val(TextBox5.Text), Val(TextBox10.Text))

    My issue is I have to enter the data in order to make my line proper. Is there a way to first arrange the points, then add them to the chart. Otherwise if I add a lesser point in the middle, it "z's" the line...

    Thanks!

  2. #2
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Arranging data points

    Start by getting the pairs into some list of( structure / class). Then you should be able to sort the items and add them to the chart. Also, look at one of the TryParse methods to convert the numeric information from text.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Feb 2011
    Posts
    71

    Re: Arranging data points

    I have found a way to make it work. Can you suggest how I should tryparse my textboxes to finish this up?

    Code:
    Dim Points As New List(Of Point)
    
            Dim P1 As New Point(Val(Me.TextBox1.Text), Val(Me.TextBox6.Text))
            Dim P2 As New Point(Val(Me.TextBox2.Text), Val(Me.TextBox7.Text))
            Dim P3 As New Point(Val(Me.TextBox3.Text), Val(Me.TextBox8.Text))
            Dim P4 As New Point(Val(Me.TextBox4.Text), Val(Me.TextBox9.Text))
            Dim P5 As New Point(Val(Me.TextBox5.Text), Val(Me.TextBox10.Text))
    
            Points.Add(P1)
            Points.Add(P2)
            Points.Add(P3)
            Points.Add(P4)
            Points.Add(P5)
    
            Dim SortedPoints As New List(Of Point)
            SortedPoints = (From pnt In Points Order By pnt.X, pnt.Y).ToList
    
            For Each GridPoint In SortedPoints
                If GridPoint.X > 0 And GridPoint.Y > 0 Then
                    Me.Chart1.Series(0).Points.AddXY(GridPoint.X, GridPoint.Y)
                End If
            Next

  4. #4
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Arranging data points

    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

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