放入p.text函数时使变量变为粗体

时间:2018-05-18 16:36:39

标签: javascript data-visualization

所以我有这个p.text函数向我显示文本,国家名称(d.properties.name)和该国家持有的值(d.properties.value) 例如,我如何使国家名称以粗体显示?

var countryHeight = d.properties.value;
var countryName = d.properties.name;
    p.text(function(countryHeight){return "The Average Height of Men in " +  d.properties.name + " = " + d.properties.value})
    .style("color", "red")
    .style("font-size", "150%")

1 个答案:

答案 0 :(得分:0)

如果要将其注入HTML页面(网页),则可以在文本函数中包含标记。

var countryHeight = d.properties.value;
var countryName = d.properties.name;
p.text(function(countryHeight){return "The Average Height of Men in <b>" +  d.properties.name + "</b> = " + d.properties.value})
    .style("color", "red")
    .style("font-size", "150%");