Adding array to Chart only plots first value - vb.net

VB.net - How come only one point is plotted?
Dim ReceivedValue As String ="1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20"
Dim myArray = Array.ConvertAll(ReceivedValue.Split(","c), AddressOf Convert.ToDouble)
Chart1.Series(0).Points.Add(myArray)
PS. I got the plot array idea from here

I get the same results as you - one point on the chart. Upon inspecting the chart's Points object, it looks like this:
Showing an array with one X=0, and an array of all the Ys.
If you do it in a loop like this, it works
For Each point In myArray
Chart1.Series(0).Points.Add(point)
Next
Now there is an actual series of points
I'm going to add what I think is more correct, because this results in actual x, y pairs with real x values (you can make them whatever you want)
For i = 0 To myArray.Count - 1
Chart1.Series(0).Points.Add(New DataPoint(i, myArray(i)))
Next

Related

how to apply xlMarkerStyles to a Chart Plot in Excel vba without directly using the xlMarkerStyleAutomatic

I have a x,y scatter chart with lines connecting the dots from one source. I have between 1 and 8 lines and I need to have the MarkerStyle assigned to each line. Since the lines are not fixed and depend on the current data, I can't say which lines are there.
In general I could just assign
ActiveChart.FullSeriesCollection(i).MarkerStyle = xlMarkerStyleAutomatic
But that also assigns unwanted/unreadable Markers. So could I create a Collection with the Markerstyles I want and than assign that?
I tested
Dim colMarker As Collection
Set colMarker = New Collection
colMarker.Add "xlMarkerStyleCircle"
colMarker.Add "xlMarkerStyleSquare"
colMarker.Add "xlMarkerStyleTriangle"
With ActiveChart.FullSeriesCollection(i)
.MarkerStyle = colMarker(1)
End With
But the error msg is wrong type
What type do I need?
Thanks Kaz
You can set the marker style for each series individually:
Dim s as Series
s = ActiveChart.SeriesCollection.NewSeries
s.MarkerStyle = xlMarkerStyleCircle
Edit:
To assign different marker styles use the approach you suggested, but when adding styles to the collection it should be done like this:
colMarker.Add xlMarkerStyleDiamond
etc, ie without quotation marks.

Change the color for each line

I got a console application that draws line in a 3D CAD program. Now to make this more clear i want to change these lines in different colors.
My code read variables from a text-file and calculates data from it and then makes a lines from this calculated data.
This process gets repeated with every line in the text file wich contains data.
Now i want visual basic to change the color everytinme a new line is drawn, so i get different colored lines.
I tried using a For.. To.. Step method, but this didnt work. I also tried to use the variables from my text file( these are different so when a new line got read the RGB code will change) but this will geve me only a lot of blue colors.
Any suggestions?
EDit:
This is what i use to draw the curves, the RGB code has to cahnge everytime when a line with new data is made:
' Creating a Curve2d object by using the above defined points
objLineString = objLineStrings.AddByPoints(PointCount:=points, points:=dataArray)
objGeometricStyle = objLineString.Style
color = objGeometricStyle.LinearColor
objGeometricStyle.LinearColor = RGB(0,0,0)
What about :
Dim rand As New Random() ' Used to generate random numbers
Dim colors(100) as Integer
' Create the colors
For i as Integer = 0 to 100 Step 1
colors(i) = RGB(rand.Next(256), rand.Next(256), rand.Next(256))
Next
For i As Integer = 0 To 100 Step 1 ' Adjust to your needs
' Creating a Curve2d object by using the above defined points
objLineString = objLineStrings.AddByPoints(PointCount:=points, points:=dataArray)
objGeometricStyle = objLineString.Style
color = objGeometricStyle.LinearColor
objGeometricStyle.LinearColor = colors(i Mod 100) ' Mod returns the remainder of i / 100, so it's always less than 100.
Next
This won't always give you "pretty" colors, but they'll be different for each line. If you want control over the generated colors, you could set up an array of predefined colors and use these in your iteration.

Add data points from Double() array to existing VB.NET chart series

I have an array of type Double() (1 x n) that I am trying to quickly plot on a graph I've already set up. The only thing I want/need to do is take my array and store it as data points (y-axis values) in the series I already have. What's the best way to do this? Also, will the data points that are plotted change as my array changes, and if not, how would I replot those new points and get rid of the old points?
Adding the points should be as simple as
Chart1.Series("Default").Points.Add(arrayName)
As for it being auto-updated when you change the array, I believe if you just add the points, you are going to have an issue like pee in a swimming pool (once they are in there, you can't get them out). So, you add an array with 3 items, then add a double to the array, then the add to the chart again, you now incorrectly have 7 points. However, you can databind the array to the series, like so.
Chart1.Series("Default").Points.DataBindXY(xStrings, xDoubles)
In this case, if the array changes, the chart should change as well.

How can I transfer the values of a 4D jagged array to a 2D standard array?

I have EuroCPCrap mapped as (j,0)(i,0) and want to put this into an array EuroCPConsol mapped as (j,i). I tried:
For j = 0 to CPIndex 'CPIndex is a global count of variables in matrix j references
For i = 0 to UBound (EuroCPCrap,3) 'i in the (now known to be) jagged
EuroCPConsol(j+1,i+1)= EuroCPCrap(j,0,i,0) 'add one since I'm base 1 but function that produced this matrix outputted base zero
Next i
Next j
I get a subscript error on the UBound statement, and I realised it's because there is no 3rd dimension in the referenced array.
First of all, I don't understand why this EuroCPCrap(j,0,i,0) would work if it's a jagged array as you describe in your first sentence. On the looks of it, it should be EuroCPCrap(j,0)(i,0).
You have a parent two-dimensional array of children two-dimensional arrays. The "third" dimension you're looking for is actually the first dimension of each child array. So something like this should work:
For i = 0 to UBound(EuroCPCrap(j,0),1)
Actually, iterating from LBound to UBound is even better practice to ensure that the entire array is traversed regardless of your Option Base or how the array is "Dimmed":
For i = LBound(EuroCPCrap(j,0),1) to UBound(EuroCPCrap(j,0),1)
Does EuroCPCrap really need to be jagged? Why not make it a 4-dimensional array? EuroCPConsol is not jagged... Is it dimensioned correctly to accept the contents of the largest of the children array? These are things to think about...

Visual Basic 6 Dynamic Variables

I am doing a program using vb6 which is stored datas from mouseclick in term of coordinates. I succeeded doing the first stage which is displaying the clicked coordinates. My problem now is I need to save the coordinate in term of variables so i can call them back to use for another purpose for example to find distance between two points.
if its just two coordinates its easier to find the distance. but when it comes to many coordinates I am stuck. I tried to do an array to stored the data inside loop
1. InputX(ListNum, 0) = Int(x)
2. InputY(ListNum, 1) = Int(y)
3. ListNum=ListNum+1
when I try to call for InputX(2,0) = Text1.Text or Text1.Text=InputX(2,0) none of them working. It seems that the data will be erased after I do a mouseclick
Is there any way which I can set the dynamic variables which stored each my clicked coordinates such as Input1,Input2,Input3 ...InputN
I do this in VB6.
The problem you're having is that you're using a two dimensional array there. A two dimensional array looks like a table. That's not what you want though. You want a list of pairs of points. So, create a structure with two integers in it, x and y, and make an array of those structures:
'Right underneath your Class Form1 declaration:
Structure Point
Dim x As Integer
Dim y As Integer
End Structure
Dim length As Integer = 10
Dim Points(length) As Point
'When you want to start using your points put this in the method:
Points(0).x = 10
Points(0).y = 10
Points(1).x = 20
Points(1).y = 40
Dynamic variables in VB6
First you declare the variable without giving size:
Dim InputX() As String
Then you give for the first time size to your array using ReDim:
ReDim InputX(5)
If you want to preserve whatever data is already in your array you use ReDim Preserve:
ReDim Preserve InputX(10)
I hope this is what you need.
it appears that the first method
Text1.Text=InputX(2,0)
is working. I just need to declare x and y As Single