【问题标题】:d3.js v7 equivalent of d3.scale.ordinal()d3.js v7 相当于 d3.scale.ordinal()
【发布时间】:2021-09-24 22:05:15
【问题描述】:

d3.js v7 等效于 d3.scale.ordinal() 是什么?我如何将它用于颜色范围?

在 v3.5.11 中我可以使用:

var colourScale = d3.scale.ordinal()
        .domain(["One", "Two", "Three"])
        .range(["#abacab", "#b67a4e", "#5a6fbb"])

        nodeUpdate.select("circle")
            .attr("r", 6.5)
            .attr("fill-opacity", "0.7")
            .attr("stroke-opacity", "1")
            .style("fill", function(d) {
                    return (typeof d._children !== 'undefined') ? (colourScale(findParent(d))) : '#FFF';
            })
            .style("stroke", function(d) {
                    return colourScale(findParent(d));
            });

我看到了使用 InternMap 作为 changes for v7 一部分的参考,但不清楚这是否会替换 scale.ordinal(以及后续版本 scaleOrdinal 和 scaleBand)以及它在上面的使用方式。

【问题讨论】:

    标签: javascript jquery d3.js


    【解决方案1】:

    d3.scale.ordinal()v4 中更改为d3.scaleOrdinalExamples here.

    所以现在你可以把上面写成:

    const colourScale = d3.scaleOrdinal()
            .domain(["One", "Two", "Three"])
            .range(["#abacab", "#b67a4e", "#5a6fbb"])
    

    Working Codesandbox running v7 here.

    希望这有帮助! ✌️

    【讨论】:

    猜你喜欢
    • 2012-10-10
    • 1970-01-01
    • 1970-01-01
    • 2023-03-15
    • 2012-09-01
    • 2013-11-26
    • 2017-01-16
    • 2019-11-20
    • 1970-01-01
    相关资源
    最近更新 更多