LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

XY Graph - How do I plot Multiple colors over one another depending on Case Structure

Hello, I have X and Y coordinates and I want the plot line color to change depending on the direction of travel (Forward, Backwards)

I found this below VI but I am not sure how to adapt it to work for my needs as honestly I dont really understand what is fully going on. I am pretty new to LabVIEW.

I understand the top sine wave is where I would need to replace it with my X,Y coordinates as an array (currently using Express XY Graph). I am not sure what the second Sine Wave (Ramp by Samples) is or what I would wire to this in my case.

The selector would be wired up approximately the same but using my signal for forwards/backwards (signal > 0Volts = Forwards).

I guess I am mostly confused about the second Sine Wave. Would I need the for loop? This is all happening in a while loop, I believe a Case selector would work better for my needs?

 

Thanks!

Gerthex_1-1678220854146.png

 

 

0 Kudos
Message 1 of 12
(1,560 Views)
  • If you have a linear x ramp, all you need is a plain waveform graph. No need for XY.
  • If you "found" a VI somewhere here, please include a link so we get some context.
  • Do you want to see both forward and backward traces at the same time?
  • Are they updated one point at a time? (i.e. having the express VI checkbox checked to retain data similar to a chart)
  • can you show us your VI draft?
0 Kudos
Message 2 of 12
(1,545 Views)

You can't change a plot on the same line to be different colors, but you can make two plots that are different colors, and make parts of them not show up.

 

The trick is that if one or both of the XY coordinates is NaN, LabVIEW won't draw it or the line connecting it.  So if you put NaNs in your data, you can make it look like a line changes colors.

 

Here's example code:

Kyle97330_0-1678224358489.png

 

Message 3 of 12
(1,544 Views)

Here's one possibility.

(rough draft: Needs some tweaks to connect all points, for example)

 

altenbach_0-1678227345784.png

 

0 Kudos
Message 4 of 12
(1,525 Views)

Gerthex_0-1678286912466.png

Here is what I have. I do not want to share my entire VI, sorry. I am not sure how make a dumbed down version of it either. I have a "build XY graph" vi and the two XY graphs seem to be following each other. the one pictured is scaling appropriately but not plotting. I am assuming I need to wire the iteration into the array but I am unsure how to do it.

0 Kudos
Message 5 of 12
(1,480 Views)

@Gerthex wrote:

 

Here is what I have.


No, that code makes absolutely no sense! Your are just creating a graph that has all the same values, duplicated N times. You need to build the history in a shift register anchored on the while loop and get rid of the FOR loop.

 

Start with some basic tutorials.

0 Kudos
Message 6 of 12
(1,471 Views)

Finally got it working how I need. Thanks all!

Gerthex_0-1678289401890.png

 

0 Kudos
Message 7 of 12
(1,470 Views)

@Gerthex wrote:

Finally got it working how I need. Thanks all!



This is just plain silly!!! Your FOR loop has absolutely no purpose, it just dramatically increases then number of identical points on the graph. After N iterations, you'll add the new value N times crazily wasting memory!. Get rid of it! (A simple build array can transform a scalar to an array with one element and that's all you need here!). Also note that the first point will never get graphed because N=0 and you get a point at the default value (0,0), which has nothing to do with your data.

 

Now you are apparently using the build xy graph express VI configured to retain data between calls (we cannot tell from a picture!). You can do exactly the same by building the data in a shift register instead. Much more lightweight!

Most programmers stay far away from most express VIs.

 

Here's what I would probably do (just change the condition to suit your needs):

 

altenbach_0-1678290704386.png

 

0 Kudos
Message 8 of 12
(1,463 Views)

Thank you for the help! I am very new to LabVIEW and programming is not my background. I am a mechical engineer trying to learn some programming to assist in our test lab. 

I am having a very difficult time picking up LabVIEW without the computer science degree a lot of people have who pick up LabVIEW quickly seem to have.

 

I will get rid of the for loop!

0 Kudos
Message 9 of 12
(1,456 Views)

Note that my solution only increments one of the plots. Your express VI adds twice as many points (50% NaNs!) for double the memory use. The NaN technique is more suitable for plain graphs.

 


@Gerthex wrote:

I am having a very difficult time picking up LabVIEW without the computer science degree a lot of people have who pick up LabVIEW quickly seem to have.


I would not be so sure about that. Seasoned text programmers tend to have good text programming habits that have no business in graphical dataflow programming so they need to unlearn a lot of things.

0 Kudos
Message 10 of 12
(1,447 Views)