|
-
Nov 4th, 2011, 11:53 AM
#1
Thread Starter
Lively Member
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!
-
Nov 4th, 2011, 11:58 AM
#2
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.
-
Nov 6th, 2011, 06:42 PM
#3
Thread Starter
Lively Member
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
-
Nov 6th, 2011, 07:33 PM
#4
Re: Arranging data points
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|