我正在尝试将文本字段添加到我在 d3.js 中创建的树状图中。我知道在 c++ 中你可以做到
string str = "again";
cout << "Hello World " + str << endl;
这将输出
Hello World again
我正在尝试这样做是d3.js但我似乎可以得到它。我尝试添加另一个文本字段,但这也不起作用。
这是我目前拥有的
cells.append("text")
.attr("x", function(d) { return d.x0 +10 })
.attr("y", function(d) { return d.y0 +27 })
.style("font", "10px times")
.text("Item count: " + function(d) {return d.data.itemCount})
.attr("fill", "white")
哪些输出
Item count: function(d) {return d.data.itemCount}
但我需要它来输出,例如,
Item count: 2042
感谢您的任何帮助
试试这个:
.text(function(d) { return "Item count: " + d.data.itemCount })
试试这个:
cells.append("text")
.attr("x", function(d) { return d.x0 +10 })
.attr("y", function(d) { return d.y0 +27 })
.style("font", "10px times")
.text("Item count: ")
.append()
.text(function(d) {return d.data.itemCount})
.attr("fill", "white")