multiple times .AddBar (ZedGraph)

Suriv

Active member
Joined
Jul 16, 2007
Messages
33
Programming Experience
1-3
I use this code to add a bar to a graph:
VB.NET:
Private Sub UpdateGraph(ByVal YValue As Double)
        Static PPList As New ZedGraph.PointPairList
        Dim PPDrawList As New ZedGraph.PointPairList
        Dim X As Double

        If PPList.Count <> 0 Then
            X = PPList.Item(PPList.Count - 1).X
        Else
            X = -1
        End If

        PPList.Add(X + 1, YValue)
        PPDrawList.Add(X + 1, YValue)

        zgcGraph.GraphPane.AddBar("", PPDrawList, Color.DarkRed)
        zgcGraph.Refresh()
End Sub

It works almost: the only problem I have is that every time I call the sub, the existing bar becomes thinner:
1st call:
attachment.php


2nd call:
attachment.php


3th call:
attachment.php


Any help would be appreciated ;).
 

Attachments

  • md.GIF
    md.GIF
    821 bytes · Views: 35
  • 2ndcall.gif
    2ndcall.gif
    648 bytes · Views: 33
  • 3thcall.gif
    3thcall.gif
    813 bytes · Views: 35
Bar becomes thinner means scale is changed.
 
You have to call AxisChange before asking for a repaint (refresh).
 
I still doesn't work with this: :confused:
VB.NET:
zgcNetwork.GraphPane.AddBar("", PPDrawList, Color.DarkRed)
zgcNetwork.AxisChange()
zgcNetwork.Refresh()
 
What doesn't work?
 
Of course they do, X-axis expands within same view.
 
Setting a fixed scale that fit what's needed should have solved it:
VB.NET:
zgcGraph.GraphPane.XAxis.Scale.Max = 20
but it don't, so you have to explore the objects and properties to see if there is a setting for the fixed width BarItem, I can't find it. Btw, each BarItem instance is returned from the AddBar method call.
 
OK, I've searched a lot, and found the solution here:
In Form_Load place this:
VB.NET:
With zgcNetwork.GraphPane
            '... other Graph init code
            .BarSettings.Type = ZedGraph.BarType.Overlay
        End With

Seems to work :).
 
Great! There are many objects to explore here, I noticed the BarType before but don't find the description of any of them to fit what you asked for. I also did try a couple of them but not this one, the description didn't even sound vaguely related to getting fixed width bars.
 
Back
Top