Click here to Skip to main content
15,888,521 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello all, I am new to vb.net & zedgraph so please be gentle...
I have the following very simplified code to add a number of zedgraph curves based on an array, but it appears to be clearing the curve on each 'for' loop?
If I comment out the zg1ppl.clear() it will generate a curve but then obviously it will accumulate all the PointPairs from all curves.
Any idea why this is happening?
(code below is muchly simplified for clarity)
VB
Dim LabelArr() As String = {"FSinDay", "FSoutDay", "APinDay", "APoutDay"}
Dim zg1ppl As New PointPairList
'loop through label array
For c = 0 To UBound(labelArr)
     'generate a set of pointpairs in the pointpairlist
     For d = 0 To 10
           zg1ppl.Add(d,d+c+1)
     Next
     'add a curve based on the pointpairlist
     myCurve = myPane.AddCurve(LabelArr(c), zg1ppl,Color.Green, SymbolType.Square)
     myCurve.Symbol.Fill = New Fill(Color.White)
     'clear the pointpairlist ready for next curve
     zg1ppl.Clear()
Next
Posted
Updated 19-Mar-13 21:15pm
v2
Comments
Prasad Khandekar 20-Mar-13 3:09am    
You have same data points for each graph.
Sherdz 20-Mar-13 3:12am    
Correct, as I said it is very much simplified, in the real code they are all different - in this case it should produce 4 curves all exactly the same, but it produces none. I will edit it to produce different curves for U.

1 solution

Hello,

How about changing your code to something as shown below. Please have a look at this[^] article, available here on CodeProject.
VB
Dim LabelArr() As String = {"FSinDay", "FSoutDay", "APinDay", "APoutDay"}
Dim zg1ppl As PointPairList
Dim x As Double
Dim y As Double
Dim rand As new Random()
'loop through label array
For c = 0 To UBound(labelArr)
    ' generate a set of pointpairs in the pointpairlist
    zg1ppl = new PointPairList()
    For d = 0 To 10
        x = (double) d + 10;
        y = (rand.NextDouble() * 5) + Math.Sin( (double) d * 0.2);
        zg1ppl.Add(x, y)
     Next
     'add a curve based on the pointpairlist
     myCurve = myPane.AddCurve(LabelArr(c), zg1ppl, Color.Green, SymbolType.Square)
     myCurve.Symbol.Fill = New Fill(Color.White)
Next
 
Share this answer
 
Comments
Sherdz 20-Mar-13 5:16am    
Thanks Prasad, I looked up everything I could find about Zedgraph before I posted.
The change here that has fixed the issue is shifting the 'zg1ppl = new pointpairlist' down instead of using the pointpairlist clear() method.
What is the difference? Why would the other way not work?
For interest the curve formula I put in was just to put something there, the curve pointpair generation in the real code is quite complex
Prasad Khandekar 20-Mar-13 5:23am    
zgp1ppl is a list is passed by reference to the addCurve method. I really don't know what's done internally in ZedGraph control to keep the copy of this point list. But if it's going to just hold the reference to it then calling .clear() will remove all points and the control may not find any information to render. Again this is a pure guess based on my past experience working with collections. I am really glad to know that your issue is fixed.
Sherdz 20-Mar-13 14:21pm    
Again, thanks for your help, really appreciate the quick response!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900