LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Rounding Values for Plots/Dials/Gauges/etc.

I have a pretty simple question, but I'm having a hard time figuring out how to do this myself, and an even harder time finding a way of wording it that helps me search for a solution online. 

 

I have gauges in my software that will adjust its maximum values depending on the units selected.  Obviously, the maximum values can be very erratic which can make the gauge look goofy. Is there any good way to take an input of a very wide range (it could be a maximum value of anywhere between 5 or 39765, for example), and adjust that value up to a decently rounded number?  So, in the case of the number being 5, 5 would actually be a good number, but in the case of 39765, I'd like it to be something like 40,000 or 50,000.  If the number were 299.75, I'd probably want it to be 300 or maybe 500.  

 

I just want the distribution of numbers to look clean on the gauge, and I should also mention that I have gauges of different sizes.  So, the number it rounds up to needs to be good across the spectrum.  

 

Any ideas or thoughts?

0 Kudos
Message 1 of 12
(1,412 Views)

You can set the max value via a property node. Another option would be to set the scale to logarithmic mapping so all ranges display well.

 

You could round to the next  higher power of 10 with the following code:

 

altenbach_0-1701798968853.png

 

Make sure to add some reasonable logic so it does not constantly flicker. For example if the value drops a bit, you might want to keep the existing limit for a while instead of constantly adjusting the upper limit.

Message 2 of 12
(1,403 Views)

@altenbach wrote:

You can set the max value via a property node. Another option would be to set the scale to logarithmic mapping so all ranges display well.

 

You could round to the next  higher power of 10 with the following code:

 

altenbach_0-1701798968853.png

 

Make sure to add some reasonable logic so it does not constantly flicker. For example if the value drops a bit, you might want to keep the existing limit for a while instead of constantly adjusting the upper limit.


That's a very helpful starting point, thank you!  I just need to find a way that numbers like 11 don't round up to 100.  I think I'm inevitably going to have to do quite a bit of logic to get this squared away.

 

And I'm only changing these values once.  They won't be jumping around.

0 Kudos
Message 3 of 12
(1,382 Views)

cwoolly_0-1701811792888.png

I think this is about what I'm looking for.  It's pretty close anyway.  

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

Hi cwolly,

 


@cwoolly wrote:

adjust that value up to a decently rounded number?  So, in the case of the number being 5, 5 would actually be a good number, but in the case of 39765, I'd like it to be something like 40,000 or 50,000.  If the number were 299.75, I'd probably want it to be 300 or maybe 500.  


For the next programming issue you better define the problem using less ambigous words like "decently", "like", "or", "probably" or "maybe".

Developing an algorithm typically starts with defining a clear problem description…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 5 of 12
(1,312 Views)

@GerdW wrote:

Hi cwolly,

 


@cwoolly wrote:

adjust that value up to a decently rounded number?  So, in the case of the number being 5, 5 would actually be a good number, but in the case of 39765, I'd like it to be something like 40,000 or 50,000.  If the number were 299.75, I'd probably want it to be 300 or maybe 500.  


For the next programming issue you better define the problem using less ambigous words like "decently", "like", "or", "probably" or "maybe".

Developing an algorithm typically starts with defining a clear problem description…


I get that, but this was a rare case where that isn't a definite standard. If there was, I wouldn't have needed to post it here because it would have been easier to solve. I was hoping someone had already faced this issue in the past. 

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

Autoscaling LabVIEW graph axes are by default set to loose fit, which is probably similar to what you want.

Message 7 of 12
(1,282 Views)

You're right about the graphs, and that's what I use for those.  I was really only looking for something to adjust my gauges' max values.  I just included plots in the title in case someone had done this for another control.

 

I also noticed that the code wasn't working very well for numbers below 500, so I made a small amendment.

cwoolly_0-1701876795420.png

 

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

Unfortunately, these are just pictures, not "code". If it takes more than 30 seconds to recreate (like my example above 😄 ), I recommend to attach a VI instead.

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

Okay, I honestly thought you could copy and paste the code here, and it was drag-and-drop into LabVIEW.  Is that not the case anymore?  I seem to remember that was a thing on these forums at one point...

 

 

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