[ACCEPTED]-Can you set style in d3 via something like foo.style({color:blah, background:blah})?-d3.js
Accepted answer
Only works on D3 v3:
To quote the documentation:
If you want to set several style 5 properties at once, use an object literal 4 like so:
selection.style({'stroke': 'black', 'stroke-width': 2})
This 3 isn't possible with functions though, so 2 in your case you still have to use the "long 1 form".
You can specify a separate function for 2 each style name in the style literal, like 1 so:
d3.selectAll(".whatever").style({
color: function(d) { return getColor(d); },
background: function(d) { return getBackground(d); }
});
The easiest way of applying multiple css 2 (static or dynamic) in d3 is to set style
as 1 many times as you need it. For example:
d3.selectAll('whatever')
.style('color', 'green')
.style('height', (d) => d + 'px');
Source:
stackoverflow.com
More Related questions
Cookie Warning
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.