Change Default d3.js colors -
i looking way alter default colors of different categories in d3.js.
i found colors laid out in main d3.js. 1 category:
var ml = [2062260, 16744206, 2924588, 14034728, 9725885, 9197131, 14907330, 8355711, 12369186, 1556175].map(yt)
i've tried replacing these values hex codes hsl rgb , never yields expected colors.
any ideas how can generate proper numbers whatever colors want?
thanks.
first, fyi, see rgb (i.e. hex) value corresponds these numbers:
(2062260).tostring(16); // 16 hex, aka base of operations 16 > "1f77b4"
next, given rgb (again, hex) want convert number:
parseint("1f77b4", 16); // 16 hex > 2062260
and number want use.
the colors got d3 source used build d3.scale.category10()
. can same thing own colors — , without modifying d3's source code — constructing d3.scale.ordinal
:
var mycategory3 = d3.scale.ordinal() .domain(["red", "#1f77b4", "rgb(128, 255, 128)"]);// kinds of colors possible mycategory3("x");// "red" mycategory3("blabla");// "#1f77b4" mycategory3("x");// "red" mycategory3(123456);// "rgb(128, 255, 128)"
d3.js
No comments:
Post a Comment