1

我有以下代码 d3 代码:

tooltip.select("#popupCount").text(function(){

if (varToGraph == "rough_top_cost"){
return " " + textValue + ": $" + addCommas(allCountyData[countyName][varToGraph]) + "\n" +
"Count:"
}})

我希望字数出现在新行上。但是,上面的代码导致所有内容都在一行上。我怎样才能让输出在两行上?

谢谢,啊

4

1 回答 1

0

未经测试的答案,但 FWIW 这可能会接近;

tooltip.select("#popupCount").html(function(){
if (varToGraph == "rough_top_cost"){
return " " + textValue + ": <br/>$" + addCommas(allCountyData[countyName][varToGraph]) + "\n" +
"Count:"
}})

从D3 Tips and Tricks第 80 页提供的示例开始工作,其中包括带有换行符的工具提示。

使用 html 元素而不是允许换行符的文本。查看文档以获取更多详细信息。

于 2013-01-02T23:53:00.190 回答