Html d3.js topojson映射的样式填充未完全填充

Html d3.js topojson映射的样式填充未完全填充,html,css,svg,d3.js,topojson,Html,Css,Svg,D3.js,Topojson,我正在尝试为地图添加颜色。当我添加填充时,我得到了一个非常奇怪的输出,其中一些颜色发生了变化,但随机的色带与以前一样。灰色图像是我添加填充之前的图像。我希望第二张地图完全是橙色的 代码如下: <!DOCTYPE html> <meta charset="utf-8"> <style> path { stroke: white; stroke-width: 0.25px; fill: grey; } </style> <bod

我正在尝试为地图添加颜色。当我添加填充时,我得到了一个非常奇怪的输出,其中一些颜色发生了变化,但随机的色带与以前一样。灰色图像是我添加填充之前的图像。我希望第二张地图完全是橙色的

代码如下:

<!DOCTYPE html>
<meta charset="utf-8">
<style>
path {
  stroke: white;
  stroke-width: 0.25px;
  fill: grey;
}

</style>
<body>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script src="http://d3js.org/topojson.v1.min.js"></script>
<script>
var width = 1200,
    height = 1200;

var projection = d3.geo.mercator()
    .center([0, 5 ])
    .scale(200)
    .rotate([-180,0]);

var svg = d3.select("body").append("svg")
    .attr("width", width)
    .attr("height", height);

var path = d3.geo.path()
    .projection(projection);

var g = svg.append("g");


// load and display the World
d3.json("us_states.json", function(error, us) {
  g.append("g")
      .attr("id", "states")
    .selectAll("path")
      .data(topojson.feature(us, us.objects.states).features)
    .enter().append("path")
      .attr("d", path)
      .style("fill", "#ffc04c"); //this is the offending line

  g.append("path")
      .datum(topojson.mesh(us, us.objects.states, function(a, b) { return a !== b; }))
      .attr("id", "state-borders")
      .attr("d", path);

});
var zoom = d3.behavior.zoom()
    .on("zoom",function() {
        g.attr("transform","translate("+ 
            d3.event.translate.join(",")+")scale("+d3.event.scale+")");
        g.selectAll("circle")
            .attr("d", path.projection(projection));
        g.selectAll("path")  
            .attr("d", path.projection(projection)); 

  });
svg.call(zoom)

</script>
</body>
</html>

路径{
笔画:白色;
笔划宽度:0.25px;
填充物:灰色;
}
可变宽度=1200,
高度=1200;
var projection=d3.geo.mercator()
.center([0,5])
.比例尺(200)
.旋转([-180,0]);
var svg=d3.选择(“正文”).追加(“svg”)
.attr(“宽度”,宽度)
.attr(“高度”,高度);
var path=d3.geo.path()
.投影(投影);
var g=svg.append(“g”);
//加载并显示世界
d3.json(“us_states.json”),函数(error,us){
g、 附加(“g”)
.attr(“id”、“状态”)
.selectAll(“路径”)
.data(topojson.feature(us,us.objects.states).features)
.enter().append(“路径”)
.attr(“d”,路径)
.style(“fill”、“#ffc04c”);//这是不符合要求的行
g、 附加(“路径”)
.datum(topojson.mesh(us,us.objects.states,函数(a,b){返回a!==b;}))
.attr(“id”,“国家边界”)
.attr(“d”,路径);
});
var zoom=d3.behavior.zoom()
.on(“缩放”,函数(){
g、 属性(“变换”、“平移”(+
d3.event.translate.join(“,”+”)比例(“+d3.event.scale+”);
g、 全选(“圆圈”)
.attr(“d”,路径投影(projection));
g、 选择全部(“路径”)
.attr(“d”,路径投影(projection));
});
调用(缩放)

问题实际上不在状态本身的
路径中(突出显示的行),而是在随后添加的状态边界中——根据CSS,这些边界以灰色填充,这就是您看到的


要修复此问题,请在CSS中为
path
s设置
fill:none

问题实际上不在状态本身的
路径中(突出显示的行),而是在随后添加的状态边界中——根据CSS,这些边界是灰色的,这就是您看到的


要修复此问题,请在CSS中为
path
s设置
fill:none

我认为问题在于你在后面添加的州边界——根据你的CSS,这些边界是灰色的,这就是你看到的。尝试在CSS中为
path
s设置
fill:none
。这就解决了问题。你想把它作为一个答案让我接受吗?我想问题是你在后面加上的州边界——根据你的CSS,这些都是灰色的,这就是你看到的。尝试在CSS中为
path
s设置
fill:none
。这就解决了问题。你想把它作为一个答案,这样我就可以接受了吗?