Saturday, September 20, 2014

D3 color consistency

If you want to get consistent colors across D3 charts, say, when using the estimable dc.js, you will need to share the color category object across the two charts. In particular, this will not work:

chart1.colors(d3.scale.category10())

...


chart2.colors(d3.scale.category10())

Instead, you want:

var mycategory = d3.scale.category10()
chart1.colors(mycategory)
chart2.colors(mycategory)

(Assuming also, of course, that the colors on each chart are based on corresponding data fields.)

No comments:

Post a Comment