D3.JS为每个国家添加课程

Mar*_*ius 4 javascript svg d3.js

我正在使用它进行简单的可视化.

http://bl.ocks.org/KoGor/5994804

我想在每个国家的路径上添加他的名字.我试图遍布各国,但我不知道与SVG联系.

var world = svg.selectAll("path.land")
            .data(countries)
            .enter().append("path")
            .attr("class", "land")
            .attr("d", path)
Run Code Online (Sandbox Code Playgroud)

joe*_*ews 5

您可以使用函数class为每个数据项动态构建属性:

var world = svg.selectAll("path.land")
            .data(countries)
            .enter().append("path")
            .attr("class", function(d) { return "land " + d.name })
            .attr("d", path)
Run Code Online (Sandbox Code Playgroud)