【问题标题】:Portion of label bold - the rest not bold部分标签加粗 - 其余部分不加粗
【发布时间】:2017-06-14 13:46:43
【问题描述】:

我正在使用d3.js,下面的 sn-p 在饼图周围呈现标签:

text.enter()
    .append("text")
    .attr("dy", ".35em")
    .style("opacity", 0.01)
    .text(function(d) {
        return (d.data.NAME + ": " + d.data.amount);
    });

所以标签可能是Jimmy: 100

如何使d.data.NAME 以粗体呈现,但d.data.amount 不应该是粗体?

【问题讨论】:

    标签: javascript css d3.js


    【解决方案1】:

    一种解决方案是为您的d.data.amount 使用具有不同font-weight<tspan> 元素。

    查看演示:

    var svg = d3.select("svg");
    var text = svg.append("text")
      .attr("x", 10)
      .attr("y", 30)
      .attr("font-weight", 700)
      .text("This is bold...")
      .append("tspan")
      .attr("font-weight", 300)
      .text(" but this is not.")
    <script src="https://d3js.org/d3.v4.min.js"></script>
    <svg></svg>

    在你的情况下,它应该是这样的:

    //...
    .style("font-weight", 700)
    .text(function(d) {
        return d.data.NAME + ": ";
    })
    .append("tspan")
    .style("font-weight", 300)
    .text(function(d) {
        return d.data.amount;
    });
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-23
    • 1970-01-01
    • 1970-01-01
    • 2012-09-02
    相关资源
    最近更新 更多