Menu

Reset GraphPane object

Help
2009-03-24
2012-09-19
  • Rafael Falcon

    Rafael Falcon - 2009-03-24

    Hi all,

    I am new to ZedGraph and I have been using it to load a data set from disk and plot it using a scatter plot.

    When I plot the first data set, everything is ok. But when I try to load another one and plot it, the chart doesn't "reset" itself but add those points to the points already plotted in the first data set. Both X and Y axes are adjusted accordingly.

    I have tried this:

    myPane = zedGraph.GraphPane;
    myPane.CurveList.Clear();
    zedGraph.Invalidate(true);

    so that all curves are removed but it seems that the already plotted points are still in the chart.

    Any help will be really appreciated.

    Thanks,
    Rafael

     
    • Jan Didden

      Jan Didden - 2009-04-02

      Rootsikal,

      PowerCurve.IsVisible=False DOES work as expected, but not outside the sub where I build my curve (LineItem actually) with:

      Dim PowerCurve As LineItem = GraphPanel.AddCurve("Power Diss.", lstPowerPoints, Color.Red, SymbolType.Circle)
      PowerCurve.IsVisible=False

      But I want to set PowerCurve.IsVisible to True or False from another sub, and that fails because the message is that PowerCurve isn't declared. I think I have a syntax problem because I'm a VB newbee...

      Alex, that link looked what I needed, but the first example already fails:

      GraphPane myPane = zg1.GraphPane

      because the message is:

      'GraphPane is a type and cannot be used as an expression'.

      I'm stuck...

      Jan Didden

       
    • Jan Didden

      Jan Didden - 2009-04-02

      .... My problem actually is as follows.
      I define a curve on my pane as follows:

      Dim PowerCurve As LineItem = GraphPanel.AddCurve("Power Diss.", lstPowerPoints, Color.Red, SymbolType.Circle)

      So far so good, curve is nicely displayed.

      Now how can I access this 'PowerCurve' object in another sub so I can do things to it, like change color, add points or make IsVisible=True.

      I did try this:

      zgGraphPanel.GraphPane.CurveList(0).IsVisible = False

      in a feeble attempt to access the first curve in the curvelist assuming that, since I only did one curve, it should be # 0 in the list.
      It didn't generate any errors or warnings but also didn't work. It did something (some stray line across the pane) but not switch on or off the curve, which is what I need.

      Any ideas?

      Jan Didden

       
    • Jan Didden

      Jan Didden - 2009-04-03

      OK, I got it!

      Using a checkbox MyCheckBox on my form, I can now switch individual curves on a graph on or off with this sub:

      Private Sub cbxMyCheckBox_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbxMyCheckBox.CheckedChanged
      Dim intCI As Integer = zgGraphPanel.GraphPane.CurveList.IndexOf("Curve Title") 'get curve index from curve title
      If cbxMyCheckBox.Checked Then
      zgGraphPanel.GraphPane.CurveList(intCI).IsVisible = True
      Else
      zgGraphPanel.GraphPane.CurveList(intCI).IsVisible = False
      End If
      zgGraphPanel.Refresh()
      End Sub

      The key is that you find the index to the particular curve you want to make visible or invisible. You can do that with the function CurveList.IndexOf("title") which uses the curve title you specified when you made the curve, or you can use the function CurveList.IndexOfTag(tag) where tag is a string you put on your curve when you made it, like: MyCurve.Tag="MyCurveTag". Either way works.

      But at the end you MUST do a Refresh() to implement the changes. What that does is erase the whole panel and then immediately redraw all the visible curves.

      Hope this is usefull,

      Jan Didden

       
    • galemor

      galemor - 2009-03-27

      I would like to know it too. Anyone kown how to do this??? please

       
    • Alex Tostevin

      Alex Tostevin - 2009-03-29

      Not an expert on this, but in my code I have:

      zg1.GraphPane.CurveList.Clear() (in vb)
      zg1.GraphPane.GraphObjList.Clear() (in vb)

      and this seems to do the trick. So perhaps a C version of the above will work?

       
    • Jan Didden

      Jan Didden - 2009-03-30

      I have a similar question. I need to selectively show and hide several curves on a graph.
      I tried to first draw the curve and then to hide it with with 'SymbolType.None' as the symbol type (found this in the documentation) but that didn't work, the graph is stilll there.

      TIA,

      Jan Didden

       
    • Alex Tostevin

      Alex Tostevin - 2009-03-30

      Jan

      Again, I am not an expert, but I would try setting the "IsVisible" part of the curve or symbol (or whatever you wish to hide) to "False".

      Hope that helps.

       
    • Jan Didden

      Jan Didden - 2009-04-01

      Hi Alex,

      Indeed, that does work inside the sub where I set up the curve on the graph panel. But how do I make that curve visible to another sub?

      I have this sub:

      Public Sub DrawPowerCurve(ByVal graphControl As ZedGraphControl)
      Dim GraphPanel As GraphPane = graphControl.GraphPane
      ....
      Dim PowerCurve As LineItem = GraphPanel.AddCurve("Power Diss.", list, Color.Red, SymbolType.Circle)
      .....
      End Sub

      Now I have another sub, called from a checkbox control and I want to do:

      PowerCurve.IsVisible = False

      But PowerCurve object isn't visible here. I'm sur eit is a trivial thing but I don't seem to Get It :-(

      Jan Didden

       
    • Alex Tostevin

      Alex Tostevin - 2009-04-01

      I see...

      How about this link:

      http://zedgraph.org/wiki/index.php?title=Edit_Data_at_runtime_after_the_graph_is_created

      This looks like it could do what you are after - let me know if it works - I have not tried this before myself.

      I guess you should try that link and then include the isvisible switch and fingers crossed!

      Alex

       
    • Rootsikal

      Rootsikal - 2009-04-02

      Hi Jan

      I'm not an expert but, in your CheckBox's function, did you try this?

      PowerCurve.IsVisible = False ;
      graphControl.Invalidate();

      rootsikal

       

Log in to post a comment.

MongoDB Logo MongoDB