d3.scale.category10()的d3.js v4.0等价物是什么? [英] What is the d3.js v4.0 equivalent for d3.scale.category10()?

查看:261
本文介绍了d3.scale.category10()的d3.js v4.0等价物是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过交互式Web可视化"书学习d3,但是4.0版已发生了很多变化.我真的不知道的一件事是,是否有d3.scale.category10()的等效项可以轻松映射到颜色.在新版本中是否存在类似的内容,还是我们需要使用math.random自己编写代码?

解决方案

代替

d3.scale.category10()

使用

d3.scaleOrdinal(d3.schemeCategory10);

创建这样的色标:

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

在与V3中相同的代码中使用这样的颜色:

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

此处阅读

参考此处

工作代码此处

I'm trying to learn d3 with the Interactive Web Visualization book, but a lot has changed with version 4.0. One thing I really can't figure out is if there is an equivalent for d3.scale.category10() to get an easy mapping to colors. Is there something like that in the new version or do we need to use math.random and code up something ourselves?

解决方案

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

这篇关于d3.scale.category10()的d3.js v4.0等价物是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆