通过css更改d3中特定文本的文本字体

changing text font through css for specific text in d3

本文关键字:文本 字体 css 更改 d3 通过      更新时间:2023-09-26

我正在使用d3框架,并试图使用css为以下元素指定字体(我想使用自定义字体,这就是我使用css的原因)。

var anchorNode = svg.selectAll("g.anchorNode").data(force2.nodes()).enter().append("svg:g").attr("class", "anchorNode");
anchorNode.append("svg:circle");
anchorNode.append("svg:text").text("test"); 

我试过使用

text {
    font: 2px Arial;
    pointer-events: none;
}

但这对这个特定的文本不起作用。我认为这是因为文本被附加到节点上。访问css中的文本的正确语法是什么?

您有到渲染的HTML或jsfiddle的链接吗?

它看起来像是附加了一个名为anchorNode的类。您可以更新该类的CSS字体:

.anchorNode {
      font-family: "Times New Roman", Times, serif;
      font-size: 2px;
}