LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Change Color on Graph

How can we change a colour on a graph after we have plot something..?
i'm using red and green colour to make a graph..
Actually what i want is to be able to make green colour invisible from my graph (transparent). also it would be good if i could change the colors at any time also..
(the plot have usually more than 15000 lines on it..)

thanks..
0 Kudos
Message 1 of 9
(4,752 Views)
Every Plot function returns you a plot handle that can be passed to SetPlotAttribute () function to customize the plot in every moment. You can use ATTR_VISIBLE attribute to hide a plot while still leaving it on the graph (i.e. you are not discarding it) and ATTR_TRACE_COLOR to change the plot colour. Severa other attributes can be set on a plot: I suggest you examine the list available in SetPlotAttribute function (also, be aware that not all attributes are available for all types of plots).


Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 2 of 9
(4,751 Views)
so i need to hold in an array all the handles?
can i do something like "change color of ALL green plots to transparent" (without using their handles..)there is a possibility to use a lot of thousends plots in a graph so this array with handles could be very big.. i'd like if it's possible to avoid the "handle" method..
0 Kudos
Message 3 of 9
(4,724 Views)


karpa wrote:
so i need to hold in an array all the handles?
can i do something like "change color of ALL green plots to transparent" (without using their handles..) there is a possibility to use a lot of thousends plots in a graph so this array with handles could be very big.. i'd like if it's possible to avoid the "handle" method..


No, not that I'm aware of.

But if you don't want to save all plot handles you could iterate through the plots and set their attributes. Simply store in a variable the handle of the last plot drawn on the grapf, then:

  • Iterate through all plots from 1 to the last plot handle, and
    • GetPlotAttribute (..., ..., index, ATTR_TRACE_COLOR, &color);
    • Get rid of "invalid plot" error that may arise in case you have ever deleted a plot from the graph
    • if (color == VAL_GREEN) SetPlotAttribute (..., ..., index, ATTR_VISIBLE, 0);


Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 4 of 9
(4,718 Views)
Thanks Robert it worked ok (i had some NON-FATAL library errors though..)
this is the code.. (i've used it with a colour numeric control)

GetCtrlVal (panel, control, &gv_freepath);
lastplothandle = PlotPoint (panel, SERIAL_GRAPH, 0.0, 0.0,VAL_NO_POINT, VAL_TRANSPARENT); //set last point
for (i=0 ; i < lastplothandle ; i++)
{
GetPlotAttribute (panel, SERIAL_GRAPH, i,ATTR_TRACE_COLOR, &colour);
if (colour==gv_old_freepath)
SetPlotAttribute (panel, SERIAL_GRAPH, i, ATTR_TRACE_COLOR, gv_freepath);
}
gv_old_freepath=gv_freepath;
DeleteGraphPlot (panel, SERIAL_GRAPH,lastplothandle , VAL_IMMEDIATE_DRAW);
0 Kudos
Message 5 of 9
(4,676 Views)

Your non-fatal errors may arise from trying to setting properties on deleted plots. Plot handles in a graph are never reused: every time you run your function you create a dummy plot to determine the final plot in the graph and iterate through plots conveniently setting the graph, deleting the dummy plot; this way you have some handles without any associated plot, so every time you try to access them you get the "invalid plot" error, as I warned you before. If you happen to delete some plots anywhere in the program this unconnected handles are even more.

To avoid annoying warnings like those, you could trap the return code from GetPlotAttribute and execute SetPlotAttribute only for actually existing plots. Apart this, you must either turn off the "break on library errors" in Run menu or use SetBreakOnLibraryErrors () function turning warnings off and on arount this part of code.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 6 of 9
(4,671 Views)
yes after i posted the code i used SetBreakOnLibraryErrors ()..

this routine (SetBreakOnLibraryErrors ()) affects only the debuger?

when i build a release does this fuction affects anyware..?
0 Kudos
Message 7 of 9
(4,668 Views)

From Checking for Errors in LabWindows/CVI chapter in CVI on-line help:

When you develop applications in LabWindows/CVI, you usually have debugging and the Break on»Library Errors option enabled. With these features enabled, LabWindows/CVI identifies and reports programming errors in your source code. Therefore, you might have a tendency to relax your own error checking. However, in compiled modules and release executables, debugging and the Break on»Library Errors option are disabled. This results in smaller and faster code, but you must perform your own error checking. This fact is important to remember because many problems can occur in compiled modules and release executables, even if the program works inside the LabWindows/CVI environment.

 



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 8 of 9
(4,657 Views)
Thanks Roberto you were very helpfull..!!
0 Kudos
Message 9 of 9
(4,638 Views)