12-05-2023 11:28 AM
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?
12-05-2023 11:57 AM
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:
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.
12-05-2023 12:59 PM
@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:
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.
12-05-2023 03:31 PM
I think this is about what I'm looking for. It's pretty close anyway.
12-06-2023 01:27 AM
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…
12-06-2023 08:22 AM
@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.
12-06-2023 09:23 AM
Autoscaling LabVIEW graph axes are by default set to loose fit, which is probably similar to what you want.
12-06-2023 09:36 AM
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.
12-06-2023 10:37 AM
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.
12-06-2023 10:40 AM
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...