This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

How change objects color at visu
#21
(10.06.2021, 06:30)admin Wrote: Use this, make sure that all lower/upper limit objects are defined and they all follow the naming scheme as you've posted.
Code:
$(function() {
  $('.color-by-value').each(function(_, el) {
    var addr = $(el).data('object');
    if (addr) {
      grp.listen(addr, function(obj) {
        var value = obj.value;
        var name = obj.name;
        var color = 'green';
        var lname = name.replace('ACTUAL_TEMP', 'LOWER_LIMIT');
        var uname = name.replace('ACTUAL_TEMP', 'UPPER_LIMIT');
        var llimit = grp.getvalue(lname);
        var ulimit = grp.getvalue(uname);

        if (value < llimit) {
          color = 'blue';
        }
        else if (value > ulimit) {
          color = 'red';
        }

        $(el).css('color', color);
      });
    }
  });
});

Fantastic!

Will try this out during the day.
There are 10 kinds of people in the world; those who can read binary and those who don't  Cool
Reply
#22
I want to change the color of a value 2 byte floating point if the value is the following I want it to change, does anyone have suggestions on how this can be solved?

0-3000 color #00991E
3001-5000 color #FF8C00
above5000 color #FF0000
Reply
#23
Use this, set additional class to color-by-value. Note that this only works in the actual visualization, not in the editor.
Code:
$(function() {
  $('.color-by-value').each(function(_, el) {
    var addr = $(el).data('object');

    if (addr) {
      grp.listen(addr, function(obj) {
        var value = obj.value, color;

        if (value <= 3000) {
          color = '#00991E';
        }
        else if (value <= 5000) {
          color = '#FF8C00';
        }
        else {
          color = '#FF0000';
        }

        $(el).css('color', color);
      });
    }
  });
});
Reply
#24
Hi, thanks for the help, but can't get it to work as expected, is this a Custom Javascript or a custom CSS?
Reply
#25
JavaScript
------------------------------
Ctrl+F5
Reply
#26
If I want to set the color of an object dependent on the value of another specific groupaddress, is it just to change from this?
Code:
var addr = $(el).data('object');

To this?
Code:
var addr = "32/3/25";
Reply
#27
If you make this change then all elements with "color-by-value" class will follow this object value. This is fine if you only need one such element. Otherwise you need to create a copy of the script with a different class name for each instance.
Reply


Forum Jump: