Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET ZedGraph
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)
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 19-Mar-13 21:04pm
Sherdz523
Edited 19-Mar-13 22:15pm
v2
Comments
Prasad Khandekar at 20-Mar-13 3:09am
   
You have same data points for each graph.
Sherdz at 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

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Hello,
 
How about changing your code to something as shown below. Please have a look at this[^] article, available here on CodeProject.
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
  Permalink  
Comments
Sherdz at 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 at 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 at 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)

  Print Answers RSS
0 OriginalGriff 285
1 DamithSL 265
2 CPallini 195
3 Maciej Los 175
4 George Jonsson 170
0 OriginalGriff 5,415
1 DamithSL 4,422
2 Maciej Los 3,820
3 Kornfeld Eliyahu Peter 3,470
4 Sergey Alexandrovich Kryukov 2,911


Advertise | Privacy | Mobile
Web02 | 2.8.141216.1 | Last Updated 20 Mar 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100