UI Interest Group Discussions

cancel
Showing results for 
Search instead for 
Did you mean: 

Customizing Waveform Chart

I have a somewhat unique functionality to put into a Waveform Chart. I am measuring two noisy signals that are related and so I want to plot them in the same Waveform Chart. The two signals are of totally different orders of magnitude, so I needed to make the Waveform Chart have two seperate Y scales. Accomplished by right clicking the default scale and clicking duplicate scale. Then when editing the properties of the Waveform Chart I was able to put Plot 1 on y-axis 1 and Plot 2 on y-axis 2. Ok, so now here is the tricky part - I also need to plot a lower limit and upper limit for both signals. For a nice sleek look, I want to use only one horizontal line for the upper limit of both signals and one horizontal line for the lower limit of both signals.

For example, say these are the limits:

Sigal 1

Upper Limit       5

Lower Limit      -2

Signal 2

Upper Limit     200

Lower Limit     100

So there would be a horizontal line plotted from -2 (on the left y-axis) to 100 (on the right y-axis) and another horizontal line plotted from 5 (on the left y-axis) to 200 (on the right y-axis). The scales would adjust automatically even if the limits or signals changed in value.

Deos anyone have any idea how to accomplish this? Right now, I can add another plot for the upper and lower limits, but the value I write into the data only corresponds to one y-axis.

Does it make sense what I'm asking for?

0 Kudos
Message 1 of 8
(6,512 Views)

You only have to have the limit plots in one scale, but you will need to control the scales so that they line up. You will need to disable the auto scaling on the Y scales and update them yourself.

If you're OK with a static scale, then this is easier, because you just do it once so that they line up. If you want to have an autoscale behavior, then it's more complex because you will need to keep the history data (or extract it from the chart) and then get the max and min for both histories to know what the limits will need to be and then you will need to align the two scales. I haven't thought about it too much, but I think you need something like this:

(Lower Limit 1 - Min 1) / (Max 1 - Min 1) will give you the relative location of the lower limit for the first plot in relation to the data (which is basically the amplitude). You do the same for the other scale and for the upper limit and then you compare them. You take the higher one for the lower limit and the lower one for the upper limit (you can even add some extra if you want to line it up nicely, such as rounding it to a multiple of 10%). Now that you have the desired relative position for the limits, you just use that the calculate the max and min values for the scales.

For example, if the lower limit for scale 1 is at 10%  and the one for scale 2 is at 18%, you decide that the lower limit should be at 20% of the scale. Let's say you then decide that the upper limit should be at 90%. So now 20% = -2 and 100 and 90% = 5 and 200 and you can use those to calculate what 0% and 100% should be and set them as the max and min of the scales.


___________________
Try to take over the world!
0 Kudos
Message 2 of 8
(4,354 Views)

wow, that is a great solution. I knew it just came down to simple math. I will try to implement this in my application and upload the code when I'm done. I have about 7 charts that will be using your scheme to update the Y scales. Do you think this would best be implemented in an xcontrol? I haven't dabbled too much with xcontrols but this seems like a good use case, especially when I want to repeat the behavior.

0 Kudos
Message 3 of 8
(4,354 Views)

This is certainly something which would be appropriate for an XControl, but you should be aware that XControls are relatively complicated and that because they don't inherit from the controls they use on their facade, the XControl will NOT have all the properties and methods that the chart has, unless you recreate them. I don't think I would recommend this as your first XControl.

Another, simpler to code, option for reuse would be a VI which does all the work and receives a chart reference as an input.


___________________
Try to take over the world!
0 Kudos
Message 4 of 8
(4,354 Views)

OK, I'm starting down the path of sub-VI with a chart ref as input.

You made the statement earlier that "If you want to have an autoscale behavior, then it's more complex because you will need to keep the history data (or extract it from the chart)."

I don't see a property node to extract all of the history data from the chart. The property node, "value," only gives the most recent data wired to the chart. Do you know of a property node or method to extract the history data or would I need to save this data as I go along?

0 Kudos
Message 5 of 8
(4,354 Views)

I believe the chart should have a history data[] property, but if it doesn't, you can create an XY chart yourself using a circular buffer. The easiest way to have a circular buffer is to use a queue with a fixed size and use the Lossy Enqueue primitive to add elements to it. You then use the queue status primitive with T wired to the return elements input to get the data in the queue.

If you do this for both the X and the Y data, you can actually wire the data into the XY graph, which allows you to have data points with arbitrary X values (as opposed to the chart, where the values are evenly spaced). The exact data types for the XY graph can be seen if you open the context help window and hover over the XY graph's terminal and there is also an example in the example finder which shows the various options.


___________________
Try to take over the world!
0 Kudos
Message 6 of 8
(4,354 Views)

I just wanted to let the community know that I abandoned this idea because it turned out to be more complex than I initially thought.

tst's implementation only works for the cases where the data points have at least one value above the high limit and below the low limit. This accounts for only one special case out of all the possibilities. I think you could just use a case structure to determine how to handle each case, but there are many cases when you start to think about it. Data points can be out of bounds from either low limit and high limit, and there are two data sets. So this makes 16 different cases.

0 Kudos
Message 7 of 8
(4,354 Views)

boochbrain wrote:

tst's implementation only works for the cases where the data points have at least one value above the high limit and below the low limit.

If the problem is only with the max and min values of the scale, then I think you can simply do a MAX(History[ ], UpperLimit)+N and use that as the max value of the scale and that will show the limit even if there is no data above it.


___________________
Try to take over the world!
0 Kudos
Message 8 of 8
(4,354 Views)