簡體   English   中英

D3.JS為每個國家添加課程

[英]D3.JS add class to each country

我正在使用它進行簡單的可視化。

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

我想在每個國家的路徑上添加他的名字。 我試圖遍布各國,但我不知道與SVG聯系。

var world = svg.selectAll("path.land")
            .data(countries)
            .enter().append("path")
            .attr("class", "land")
            .attr("d", path)

您可以使用函數為每個數據項動態構建class屬性:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM