D3.js v5 schemeCategory 库未定义

D3.js v5 schemeCategory library undefined

我最近一直在学习 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