Updating Graphs

Hi

I would like to create a graph inside an existing window which was created as follows:
DoWindow/F Window1  <br />
Execute "Window1()"

where
Window Window1() : Panel<br />
NewPanel /W=(230,53,881,791) as "Window1 Title"<br />
...<br />
Display/N=graph/HOST=#/W=(30,377,629,723)<br />
EndMacro<br />

If I understand correctly, this creates a graph inside the panel 'window1' (the currently active window) with name 'graph'.
I am then trying to append traces to this graph from another function via
AppendToGraph/W=graph wave1 vs wave2<br />

which throws the following error

While executing ApendToGraph the following error occured: there are no graphs or the specified graph does not exist.

If I change the AppendToGraph to the following line
AppendToGraph/W=# wave1 vs wave2<br />

everything works fine. However, on repeated execution of the function, the graph does not update? Also is there a way to empty the graph (i.e. to remove all appended traces?).
Any help is much appreciated :).

Thanks,
lin
Hello Lin,

Even if it's working, have you also tried this ? :
AppendToGraph/W=Window1#graph wave1 vs wave2 //see SubWindow syntax


Sometimes, the SetActiveSubWindow instruction may be useful too.

Regarding the other stuff, I think your problem is that you always append the traces, even if they have already been appended.
I would suggest to define a boolean variable to know if the trace was already plotted or not.
variable /G bool_Plotted = root:bool_Plotted

If (bool_Plotted == 0)
    AppendToGraph/W=Window1#graph wave1 vs wave2
    bool_Plotted  = 1
Else
    Print "Trace already plotted"
Endif

So that, no need to explicitely update anything.

Best Regards
Rather than using a global to keep track of what has been plotted, use the CheckDisplayed operation to check if the wave is already displayed in the graph.
Another little tip you might find useful is that operations that create windows (like Display and Newpanel) when run in a function create a string variable called S_name that contains the name of the created window or subwindow. Here's a trivial example function that collects a full path to a subwindow:
function test()

    NewPanel
    String fullpath = S_name
    Display/HOST=$fullpath
    fullPath += "#"+S_name
    print fullPath
end
You could use the string fullPath later to refer to your graph window. In code, it's generally a good idea to explicitly name windows, rather than depending on the active window. So instead of writing AppendToGraph, write something like
AppendToGraph/W=$fullPath ...

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com