2014-03-12 71 views
0

我正在使用d3创建地球仪。我想要改变国家的填充颜色,取决于它们是否在一个名为“无代表性”的数组中。但我无法改变填充颜色。我有错误的语法吗?重置d3中的填充颜色

d3.json("world-countries.json", function(collection) { 

     feature = svg.selectAll("path") 
       .data(collection.features) 
       .enter().append("svg:path") 
       .attr("d", clip) 
       .attr("id", function(d) { return d.id; }) 
       .on("mouseover", pathOver) 
       .on("mouseout", pathOut) 
       .on("click", click); 

      feature.append("svg:title") 
       .text(function(d) { return d.properties.name; }); 

      feature.each(function(){ 
      thisOne = $(this).attr('id'); 
      for (var i=0; i<unrepresented.length; i++){ 
       if ($(this).attr('id') == unrepresented[i]) { 
        thisOne.style("fill", "#000000");; 
       } 
      } 
      }); 


}); 

回答

1

thisOne是代码中节点的ID - 您无法在其上设置样式。下面的代码应该工作:

d3.select(this).style("fill", "#000000"); 
+0

我做了改变,但现在它引发错误:错误:问题解析d =“” – LauraNMS

+0

这是一个无关的错误。你可以发布一个完整的工作示例吗? –

+0

不,我的代码还有其他问题。你的回答是对的。谢谢,拉尔斯! – LauraNMS