02-02-2009 04:38 AM
I'm having trouble completely clearing and resetting a graph... I'm not even sure if this is possible.
I generate a graph on a seperate panel. Now if I close the panel, I want to be able to generate a new graph with new settings.
I'm calling DeleteGraphPlot (int panelHandle, int controlID, int plotHandle, int refresh); with the -1 option for plotHandle, which erases all plots on my graph.
The first problem now is -> the legend isn't cleared
I could call ClearLegend, but I read that it actually only hides the items... which is not the behaviour I want.
Also the plotHandles don't seem to reset. This is causing a few troubles while generating a new graph and adding the correct label to the legend since all old handles still seem to be there (but my routine starts to count from 1 again).
Am I missing something? Or is this simply not possible?
I'm using LabWindows/CVI 8.5.
Solved! Go to Solution.
02-02-2009 06:58 AM
Hi, while I cannot say anything about legend, I can assure you that plot handles are not reused when a plot is deleted. There is an interesting discussion about it here.
A good solution for your problem is to create an array of plot handles were to store them while plotting and from were to read back the handles when you need to customize some plot.
You could also try deleting all the plots and legends, duplicating the control and deleting the existing one just to see if the new one still retains plot IDs from the old graph: I never tried it since I prefere the first solution I mentioned.
02-02-2009 07:47 AM
Thanks for your reply!
If I understood correctly from the thread you posted:
Calling GetCtrlAttribute (panelHandle, PANEL_GRAPH, 20465, &numPlots); should return the number of plots, taking deleted ones into consideration.
Doesn't seem to work though, at least it doesn't when you delete ALL the plots. In this case this function returns 0 (zero).
Nevertheless it did point me to the right direction. I'm now using a global variable which is incremented with the number of plots written every time I generate a graph.
The problem with the legend not being cleared correctly seemed to have solved itself. It seems it was just acting up wrong, when I was accessing plots that weren't present anymore.
Everything's working now as it should be. So thanks for pointing me to the solution 😉
Out of curiosity....any idea what happens with the "deleted" plots? Is the memory being freed or does it increase with every new graph I plot?
02-02-2009 08:08 AM
I don't know exactly what happens when you delete a plot, but keep in mind that not necessarily a graph has some memory allocated on the plots: disabling the attribute COPY_ORIGINAL_PLOT_DATA makes the graph store only a pointer to the array of data and do not maintain a copy of them, so there is no memory allocation on this. But according to CVI help the savings are not significant in comparison to the overall amount of memory that LabWindows/CVI uses.
As far as I can understand from the documentation, the more memory-consuming option is smooth updating, since it creates an offscreen bitmap image of the whole control. Nevertheless, smooth updating improves graph performances and I usually let it enabled. Knowning nowadays computer characteristics, in my opinion it's difficult to run low in memory (and in my experience I never was!).
02-02-2009 11:51 AM
Memory is indeed associated with each plot -- even if you disable COPY_ORIGINAL_PLOT_DATA (just not as much) And when you call DeleteGraphPlot this memory is freed.
"Smooth Update" does use a significant amount of memory (and it also slows down the initial plotting time a bit) but the amount of memory that is uses is proportional only to the size of the graph, and not to the number of plots or to the amount of data in each plot. So, if someone were to plot several very, very large data buffers (and people do do this), then the amount of memory used with "Smooth Update" pales in comparison with the amount of memory used by the plots themselves.
It really helps to think of each plot id as an object handle, rather than an index in a list, for example. In this sense, it's no different from a control id. The fact that the numbering of the handles is consecutive and increasing should be of incidental interest only. These objects are created when you plot them, and disposed when you call DiscardGraphPlot. Of course, being able to enumerate the plots would help, I admit... The enumeration attributes (ATTR_NUM_PLOTS, ATTR_FIRST_PLOT, ATTR_NEXT_PLOT) were finally added in CVI 9.0. In older versions, you have to use 20465, 20466 and 21482, respectively.
Also, I'm somewhat surprised that you had a stale plot problem with the legend (the old plots reappeared in the legend when you tried to use a deleted plot id???) What functions were you passing the bad plot ids to, that caused this to happen?
Luis