原回答:
(v5) D3 no longer provides the d3.schemeCategory20* categorical color schemes. These twenty-color schemes were flawed because their grouped design could falsely imply relationships in the data: a shared hue can imply that the encoded data are part of a group (a super-category), while relative lightness can imply order. Instead, D3 now includes d3-scale-chromatic, which implements excellent schemes from ColorBrewer, including categorical, diverging, sequential single-hue and sequential multi-hue schemes. These schemes are available in both discrete and continuous variants.
翻译过来是说:
D3的v5版本不再支持 d3.schemeCategory20
了. 因为这个方案的分组设计可能错误地暗示了数据中的关系:共享的色调可能意味着编码数据属于一个组(一个超类别),而相对的亮度可能显示出顺序.
D3现在使用的新颜色方案叫做 d3-scale-chromatic
, 它实现了来自ColorBrewer的优秀方案,包括分类、发散、顺序单色调和顺序多色调方案。这些格式可用于离散和连续变量。
v5版本设置颜色的方法可以参考我的另一篇文章:
力引导图设置多种节点颜色