问问题
7583 次
1 回答
5
You appear to be making one large map, not a series of path
objects representing countries. Try this:
d3.json("map_topo.json", function(error, map) {
svg.selectAll("path")
.data(topojson.feature(us, us.objects.counties).features)
.enter()
.append("path")
.attr("d", path)
.style("fill", function(d) {
if (d.properties.region == "XYZ")
{return "red"}
else {return "gray"}
});
I can't be sure this will work without seeing the TopoJSON file, but basically you need a topojson
method that will produce an array.
See the choropleth map example for a good example: The states are mapped as one path with .mesh()
while the counties are mapped as individual objects like the code above.
于 2013-04-30T17:18:58.163 回答