Click here to Skip to main content
11,496,146 members (789 online)
The site is currently in read-only mode for maintenance. Posting of new items will be available again shortly.
See more: VB.NET ZedGraph
Hello all, I am new to & 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
     '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
Posted 19-Mar-13 21:04pm
Edited 19-Mar-13 22:15pm
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


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)
     'add a curve based on the pointpairlist
     myCurve = myPane.AddCurve(LabelArr(c), zg1ppl, Color.Green, SymbolType.Square)
     myCurve.Symbol.Fill = New Fill(Color.White)
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 Dnyaneshwar@Pune 692
1 RyanDev 230
2 CHill60 163
3 Sascha Lefèvre 145
4 Sergey Alexandrovich Kryukov 124
0 Sergey Alexandrovich Kryukov 10,401
1 OriginalGriff 8,910
2 Sascha Lefèvre 3,899
3 Maciej Los 3,422
4 Richard Deeming 2,600

Advertise | Privacy | Mobile
Web03 | 2.8.150520.1 | Last Updated 20 Mar 2013
Copyright © CodeProject, 1999-2015
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