What is the d3.js v4.0 equivalent for d3.scale.category10()?

Instead of

d3.scale.category10()

use

d3.scaleOrdinal(d3.schemeCategory10);

Create a color scale like this:

var color = d3.scaleOrdinal(d3.schemeCategory10);

use the color like this in the code same as in V3:

svg.append("rect")
.attr("x", 10)
.attr("y", 10)
.attr("width", 100)
.attr("height", 100)
.style("fill", color(3))

read here

Reference here

working code here

Leave a Comment

techhipbettruvabetnorabahisbahis forumu