29.12.2021, 13:29
Hi,
I would like to change the color of the svg icon in visualisation based on it's value.
On the internet I found that the css attribute 'fill' should do the job but it doesn't.
The script itself works, if I alter it to change the background of the 'icon' element, it changes color accordingly.
How can I make it changes the color of the svg?
Thanks!
I would like to change the color of the svg icon in visualisation based on it's value.
On the internet I found that the css attribute 'fill' should do the job but it doesn't.
The script itself works, if I alter it to change the background of the 'icon' element, it changes color accordingly.
Code:
icon.css('background-color', color);
How can I make it changes the color of the svg?
Code:
$(function() {
$('.bgcolor-by-value').each(function(i, el) {
var $el = $(el), addr = $(el).data('object'), icon = $el.find('.icon');
if (addr) {
grp.listen(addr, function(obj) {
console.log(icon.get(0), obj.value);
var value = obj.value
, color = 'green'; // default color
if (value >= 3 && value <= 4) {
color = 'orange';
}
else if (value >= 5) {
color = 'red';
}
icon.css('background-color', color);
});
}
});
});
Thanks!