This particular formula type is designed to modify the input data you select as a variable within your widget. You have the option to choose between two different source types for this formula: Fixed or Variable.
Source of the formula
You can choose to enter your formula directly into the Fixed field or select a variable to contain the formula in the JSON field labeled 'value'. If you opt to use the Fixed field, simply enter the formula directly into the widget.
When selecting a Variable as the source for your formula, make sure to select the appropriate variable and ensure that the formula is stored in its 'value' field. Additionally, you can add a 'unit' to the variable, which can be used to display the value later. For instance, if you have a variable that converts temperature from Fahrenheit to Celsius, it might look something like this:
"unit" : "°C",
"value" : "($value$-32)*5/9"
These are some of the operators available for you to use:
|+, -||add, subtract||$value$ + 1000|
|/, *||divide, multiply||$value$ / 2.14|
|to, in||unit conversion||$value$ inch to cm|
|? :||conditional expression||$value$==1 ? $VALUE$ ON : OFF|
|>>, << ||arithmetic shifts||$VALUE$ >> 1|
|sqrt, sin, log||math operations||sqrt ($value$)|More options for Operators can be found on Math.js.
Because not all options are available for the Formula, make sure you test it before deploying your solution.
You can also use input fields other than $value$; for example:
|JSON Field||Example |
|$unit$||equalText('$UNIT$', 'C') ? $VALUE$ degC to degF : $VALUE$|
|all JSON fields||$*$|
Let's say that you want to visualize a 'temperature' in Fahrenheit, but your device stored it in Celsius, you can use one of these formulas:
$VALUE$ celsius in fahrenheit
$VALUE$ degC to degF
($VALUE$ × 9/5) + 32
More examples are available in the dropdown list in the Formula field.
You can see more options by accessing the Evaluate session of the Math.js documentation that we used as a reference.
Units for the output variables
In the example above, you will want to see the output value showing the unit °F, instead of the original °C because you converted the value to a new scale.
You have options to define the origin of the unit to be displayed using the field Unit Origin. Learn the options to Display Units.
Minimum and Maximum limits
The formula will not adjust the limits of the widgets. The Min and Max values of the range are still solely controlled by the settings defined in the 'Data Range' tab.
Dynamic Formulas work differently than its simpler counterpart as it enables you to use formulas in conjunction with your end-users preferences. This means that your users can decide what best suits their needs and the application will automatically adjust itself to the user's configured preference.