我最近一直在学习 d3.js,正在创建一个散点图,该散点图将使每个数据点根据其类别使用不同的颜色。对于这一点,到目前为止我查看过的所有资源都指出我使用 d3.schemeCategory 进行序数标签。
我的主要问题是,schemeCategory 库似乎每次我调用它时都未定义(或它的任何变体)。我想知道这是否仅限于我,或者其他人是否也遇到过同样的问题。
请注意每当我使用http://d3js.org/d3.v5.min.js/
或~/d3.v5.js
我总是收到 MIME 错误。所以我一直在使用 d3.js 版本 5 包,可以从他们的网站下载。
下面是一些上下文的代码片段:
colorScale = d3.scaleOrdinal()
.domain(regionSet)
console.log(d3.schemeCategory20)
//.range(d3.schemeCategory20);
其中 regionSet
是使用的类别。 console.log 命令的输出只是 undefined
感谢任何和所有反馈。
最佳答案
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 Repo
您应该使用D3 Scale Chromatic相反。
关于javascript - D3.js v5 方案类别库未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58416439/