12,404,251 members (79,378 online)
Rate this:
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)
```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
Next
'add a curve based on the pointpairlist
myCurve.Symbol.Fill = New Fill(Color.White)
'clear the pointpairlist ready for next curve
zg1ppl.Clear()
Next
```
Posted 19-Mar-13 20:04pm
Sherdz539
Updated 19-Mar-13 21:15pm
v2

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.

Rate this:

## 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);
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```
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

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!

Top Experts
Last 24hrsThis month
 OriginalGriff 278 Richard MacCutchan 247 Suvendu Shekhar Giri 225 Karthik Bangalore 210 ppolymorphe 145
 OriginalGriff 7,386 ppolymorphe 3,175 Karthik Bangalore 3,127 Richard MacCutchan 2,372 F-ES Sitecore 2,262